Author Topic: TCPObject.listen();  (Read 877 times)

So, I'm trying to send text via a TCPObject connected to an ip and a port. I have also set up another TCP listening on the same port. I'm also echoing [TCPObjectname]::OnLine. I can get it to send but it will always echo 'Got bad connect receive event' I have tried all the BL ports and a few others I have forwarded. Is this to do with the ports of am I forgetting something with listen?

Tom

I think the listen function is messed up.

BobAndRob posted something about all this, just ran through it all in console for a quick test.

For connecting to a Torque TCPobject, the 'server' tcpobject needs an onConnectRequest function, which should look roughly like this:
Code: [Select]
function ServerTCP::onConnectRequest(%this,%ip,%socket)
{
   if(isObject(%this.connection[%ip]))
   {
      echo(%this.getName() @ ": Got duplicate connection from" SPC %ip);
      %this.connection[%ip].disconnect();
      %this.connection[%ip].delete();
   }
   echo(%this.getName() @ ": Creating connection to" SPC %ip);
   %this.connection[%ip] = new TCPobject("",%socket) { class = ConnectionTCP; parent = %this; };
}
function ConnectionTCP::onLine(%this,%line)
{
   // do stuff here
}

Obviously this is just an example but you should be able to figure out what to do with it from there.

I would try and find BobAndRob's post about this though, I have no idea where it was and I'm too lazy to look but I'm sure he probably explained it properly.

Tom

Oh awesome I can work on my remote control now.

Thanks M, I completely forgot about creating a new object for the client