Author Topic: "Got bad connected receive event." error from listening TCPObject  (Read 1153 times)

I made the following test code to try setting up a simple TCP server.
Code: [Select]
new TCPObject(TCPListener);
$ListenOn = 31337;

function TCPListener::onConnectionRequest(%this, %addr, %id)
{ echo("Got a connection from {"@%addr@"}: "@%id); }
function TCPListener::onLine(%this, %line)
{ echo("Got line \""@%line@"\"."); }
TCPListener.listen($ListenOn);

new TCPObject(TCPTalker);

function TCPTalker::onConnected(%this)
{
echo("Successfully connected.");
%this.send("Test\r\n");
}

function TCPTalker::onDisconnect(%this)
{ echo("Got disconnected."); }

However, when I try to connect to the listener, I get this:
Quote from: Console
==>TCPTalker.connect("10.1.1.44:31337");
Successfully connected.
Got bad connected receive event.


Does anyone know what the problem is?

I haven't done much tcpobject work

But FYI (doubt its the problem, especially if the client and server are on the same machine) I've heard that port 31337 was often used by malware and some software and ISPs block traffic on it

In the tcplistener::onconnectrequest, you need to instantiate a new TCPObject to hold the connection

In the tcplistener::onconnectrequest, you need to instantiate a new TCPObject to hold the connection

Do I call .connect on the new TCPObject, or do I just make it?

Do I call .connect on the new TCPObject, or do I just make it?
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.