Author Topic: TCPObj: Disconnecting after send();  (Read 592 times)

Tom

TCPObjs are supposed to stay connected, right? For some reason every-time i use send();, it disconnects after the file is sent.

Code: [Select]
if(!isObject(TCP))
{
new TCPObject(TCP)
{
   site = "http://forum.blockland.us";
   port = 80;
};
}

function tcp2()
{
TCP.connect("forum.blockland.us:80");
}

function TCP::onConnected(%this)
{
$file="/index.php?;wap2";
$url="forum.blockland.us:80";
%this.send("GET "@$file@" HTTP/1.0\nHost: " @$url@"\nUser-Agent: Torque\n\r\n\r\n");
echo("CONNECT");
}

function TCP::onDisconnect(%this)
{
echo("DISCONNECTED");
}

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



No, they're supposed to disconnect.
I think.

HTTP is not a stream - you send a request to the server, it replies then disconnects you. Unless you use HTTP/1.1 keep-alive directives but that'd be getting a bit complicated for what you're doing.

Tom

HTTP is not a stream - you send a request to the server, it replies then disconnects you. Unless you use HTTP/1.1 keep-alive directives but that'd be getting a bit complicated for what you're doing.
So I need to check to see if its connected before sending a request, and if its not do the connect function and then send it?

You would need to check that it was connected and that you hadn't already used it to send a GET/POST or it'll overwrite the last one and you won't get a response back.

Tom

Also, I want some info on HTTP 1.1 keep alive stuff, I night need it for Remote Server control.

It shouldn't be used for persistent connections like that.