Game Development Community

Tcpobject

by GSK · in Torque Game Engine · 08/29/2008 (7:18 am) · 2 replies

Hi

I've got a problem with TCPObject. I am trying to connect to a tcp server, currently for testing purposes only. The following code

function tcpClient::onConnected(%obj)
{
   echo("TCPClient connected");
}
function tcpClient::onDNSResolved(%this)
{
   echo("TCPClient DNS resolved");
}
function tcpClient::onDisConnect(%obj)
{
   echo("TCPClient disconnected");
}
function tcpClient::onConnectFailed(%obj)
{
   echo("TCPClient connect failed");
}
function tcpClient::onLine(%this, %line)
{
   echo("TCPClient line received: %s", %line);
}


function doWorldLogin()
{
   echo("executing doWorldLogin()");
   new TCPObject(tcpClient);

   tcpClient.connect("xxxxxx.xxxxxxxx.org:80");
   tcpClient.send("GET\n");
   tcpClient.disconnect();
   
}

is linked to a button in the MainMenuGui (instead of xxxxx.xxxxxx.org:80 a real address is used) . Pressing either the button or calling doWorldLogin() from the console does nothing (it seems, because none of the callbacks ever get called) other than the echo(). BUT when I manually enter into the console:

tcpClient.connect("www.apache.org:80")
tcpClient.send("GET\n")

everything seems to work perfectly well (the onLine() callback receives the complete html for apache's main page as expected)

Clueless as to my mistake (probably something pretty stupid as I am only starting out with torque)

Any help would be largely appreciated!

Thanks
Gerhard

About the author


#1
08/29/2008 (11:21 am)
You can try to send the GET after the socket is connected and close / delete it after you got all content.
#2
08/29/2008 (11:41 am)
Thanks Thomas.

You put me on the right track there. I, wrongly, assumed that connect() would only return after the underlying socket actually was connected. Thats not the case though. Moving the send() into the onConnected() callback fixed it.

rgds
Gerhard