Game Development Community

TCPObject Listen()

by Matt-C · in Torque 3D Professional · 03/20/2010 (2:49 pm) · 5 replies

I currently have my torque game server listening on an additional port using the listen() command...

new tcpobject(gamelogin);
gamelogin.listen(5010);

at which point I have my torque client connecting and triggering my onConnectRequest event...

At such time I am assigning it a new object name.

new TCPObject(newclients, %id);

However once one client is connected I end up recieving the following error for each client afterwords...

134: Cannot re-declare object [newclients].

and such if i make "newclients" a variable I do not know how to trigger future incoming responses via that socket...

as I have the following below...

function newclients::onLine(%this, %line){
newclients.processLine(%line, %this);
}

and if i made it a variable it would have to be something like.. (which won`t work)

function "newclients @ 1450" @ ::onLine(%this, %line){
newclients.processLine(%line, %this);
}


Anyone have any suggestions on dealing with multiple connections on the same listen port, and being able to identify them seporately...

Hopefully it is something simple that I have just overlooked..

#1
03/20/2010 (4:18 pm)

T3D won't let you redefine global objects by default. The solution is to simply remove the "newclients" in the object definition above.

new TCPObject( , %id );

To associate behavior with the object, use "class" or "superClass":

new TCPObject( , %id )
{
   class = MyConnectionClass;
};
#2
03/29/2010 (3:12 pm)
Thanks for the Reply Rene, and my apologies for the delay as I have been crazy busy lately..


I had some time to work on things tonight, and tried a few things this is where I ended up.(See Below)

And things are "better" in the sense that I can now make multiple connections to that "Socket", without getting issues of it being already declared, in use, etc.. but incoming "Packets" are not triggering the onLine & processline functions.

Hopefully it is something simple, or I am completely off base.. Any help would be appreciated as I am a programmer by hobby not profession.

Here is my code... although highly edited so that only the meat and potatoes are included below;

new tcpobject(gamelogin);
gamelogin.listen(5010);
function gamelogin::onConnectRequest(%this, %address, %id)
{
new Object(clientbase) {};
%somevar = new TCPObject( , %id)
{
class = clientbase;
};
}
function clientbase::onLine(%this, %line){
echo("On line ");
clientbase.processLine(%line, %this);
}
function clientbase::processLine(%this, %line, %id)
{
if(%line!$= "")
echo("ID " @ %id @ " " @ %line @ "");
else
echo("Blank Login Packet Recieved ?????????");
}
#3
03/29/2010 (3:33 pm)

Sorry, I missed something here. The code I posted above which is making use of 'class' on TCPObject will actually only work in the not yet released beta 2.

Torque always had this (in my eyes very pointless) system that required classes to explicitly enable namespace linkage on their objects. Without this, 'class' and 'superClass' would not work on an object.

Since TCPObject did not do that, the fields won't work.

In the upcoming version, this is entirely removed and 'class' and 'superClass' works on all objects. Additionally, 'superClass' has much improved functionality and allows for deeper class hierarchies.

As for the b1 codebase, I'm actually a bit stumped by the question how you would achieve what you are going for here. There's $Con::redefineBehavior but I just found out we have no way to revert to TGE behavior with that. You could name all your clientbase TCPObjects differently, but then you need to define the functions for all these namespace to link back to what you want. Argh.

So, in short, this all isn't a problem in b2 but in b1 (and by extension 1.0.1) this is a real problem where the new TS behavior of disallowing redefinition turns this into a very tricky business.
#4
03/30/2010 (4:24 pm)
Definately glad to hear that this is getting sorted out with the next release of 1.1.

I did a quick search and combed through the various issues/bugs that have been reported however didn`t come across this one per say... Would you be able to provide a link as I would like to follow it's status and ensure that I catch any follow-ups on that thread as well.

Also one more question with my above code.... assuming the issue is corrected with the next release did you see any issues with my syntax/structure am I going about it the right way ?

Thanks in advance!

Matt
#5
03/30/2010 (5:05 pm)

The 'class' and 'superClass' stuff definitely works with the next beta.

As for you snippet above, you still have a named object defined locally in the onConnectRequest function. That will lead to redefinition errors.