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."); }
==>TCPTalker.connect("10.1.1.44:31337");Successfully connected.Got bad connected receive event.
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?
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.
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}