Author Topic: TCP client and server not sending lines [SOLVED]  (Read 746 times)

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).
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?
« Last Edit: February 28, 2014, 06:34:37 PM by Hammereditor5 »

Well, first off, copying other people's scripts isn't a great way to refresh your memory on how to use things.

Well, first off, copying other people's scripts isn't a great way to refresh your memory on how to use things.
I know that I copied that guy's script.
I just edited the OP to mention this.
« Last Edit: February 25, 2014, 03:35:30 PM by Hammereditor5 »

What OS are you using?


Why are you creating a TCPObject named ClientTCP instead of TestClientTCP?

Why are you creating a TCPObject named ClientTCP instead of TestClientTCP?
Forget about it. I already fixed the issue.