31
Modification Help / TCP client and server not sending lines [SOLVED]
« on: February 25, 2014, 03:09:40 PM »
EDIT: I now solved the problem by using a different method to run a server socket.
I created a small script today to refresh my memory on how to use TCPobjects (I've not used them for over 6 months).
I created a small script today to refresh my memory on how to use TCPobjects (I've not used them for over 6 months).
Code: [Select]
function ServerTCP::onLine(%this, %line)
{
echo(%this.getName() @ ": Line received from client: " @ %line);
}
//The 'ServerTCP' and 'ClientTCP' classes are copied and modified from another forum topic.
function ServerTCP::onConnectRequest(%this, %ipAddr, %socket)
{
if(isObject(%this.connection[%ipAddr]))
{
echo(%this.getName() @ ": Got duplicate connection from" SPC %ipAddr);
%this.connection[%ipAddr].disconnect();
%this.connection[%ipAddr].delete();
}
echo(%this.getName() @ ": Creating connection to" SPC %ipAddr SPC "...");
%this.connection[%ipAddr] = new TCPobject("",%socket) { class = ClientTCP; parent = %this; };
}
function ClientTCP::onLine(%this, %line)
{
echo(%this.getName() @ ": Line received from client: " @ %line @ ". Echoing to client...");
%this.send("Echo of your line:" SPC %line);
}
function ClientTCP::onConnected(%this)
{
echo(%this.getName() @ ": Client has successfully connected to the server.");
}
function TestClientTCP::onLine(%this, %line)
{
echo(%this.getName() @ ": Line received from server: " @ %line);
}
function TestClientTCP::onConnected(%this)
{
echo(%this.getName() @ ": Successfully connected to server.");
}
new TCPobject(ServerTCP);
ServerTCP.listen(3009);
//Create a client to test:
$testClient = new TCPobject(ClientTCP);
$testClient.connect("127.0.0.1:3009"); //the TCP server is hosted on the same computer which the TCP client is on
//Now the console echoes "ClientTCP: Successfully connected to server.", and then "ServerTCP: Creating connection to 127.0.0.1:52771...".
$testClient.send("Testing...\r\n");
//Now nothing happens. No text or error messages are echoed inside the console.
As you can see, the ::onLine() function is never being called. Is anything wrong in this code?