Game Development Community

Tcpobject onLine problem

by Bisher Tarakji · in Torque Game Engine · 08/31/2006 (2:21 am) · 5 replies

Hello
I am having a very strange problem with a simple tcpobject code

function log()
{
%tcpobj = new TCPObject(AuthTCP);
%tcpobj.connect("www.yahoo.com:80");
echo("connected");
%tcpobj.send("GET / \r\n");
}

function AuthTCP::onLine(%this, %line)
{
echo(%line);
}

function AuthTCP::onDisconnect(%this)
{
echo("disconnection occured.");
}

I get the "connected" echo message, and when i disconnect, i get the "disconnection occured" message.
But the onLine function is never called.
I tried to telnet to port 80 on the site, and i got many lines, so I don't understand what's wrong with the onLine function and why it is not executing

thanks

#1
08/31/2006 (3:24 am)
Your GET command is not correct. You have to supply more arguments.

For example:
%tcpobj.send("GET folder/file.ext HTTP/1.1\nHost: www.site.com\nUser-Agent: Torque/1.0 \n\r\n")

If your server does not support HTTP 1.1, then change that argument to 1.0.
#2
08/31/2006 (1:25 pm)
This is not the issue. If you issue the same command using telnet, you get so many lines, and thus the onLine method should be invoked
thanks anyway. Any more suggestions?

thanks for all
#3
08/31/2006 (1:29 pm)
What's the point with asking for help if you dont try the suggestions you get?

I have used TCPObject extensively, and I can say for sure that the line you posted has never worked. If you supply the wrong HTTP version tag, you also wont get a reply.
#4
08/31/2006 (1:59 pm)
First of all... your code as written won't work no matter how you format the GET line. You're sending the request BEFORE you are actually connected. Change your code to the following:

function log()
{
  %tcpobj = new TCPObject(AuthTCP);
  %tcpobj.connect("www.yahoo.com:80");
}

function AuthTCP::onConnected(%this)
{
  echo("connected");
  %this.send("GET / \n\r\n");
}

function AuthTCP::onLine(%this, %line)
{ 
  echo(%line);
}

function AuthTCP::onDisconnect(%this)
{
  echo("disconnection occured.");
}

Second... You really should at a minimum tell the server that you are sending an HTTP/1.0 GET request:

%this.send("GET / HTTP/1.0 \n\r\n");

I would encourage you to read RFC1945 (HTTP 1.0) and RFC2616 (HTTP 1.1) if you intend to use TCPObject to do HTTP requests.