Page 1 of 1

Way to determine if Server closed the connection

Posted: Wed Feb 09, 2011 6:07 pm
by Marlin
Help wrote:CloseNetworkConnection()
...
Close the specified connection. If a client calls this, the server will recieve a #PB_NetworkEvent_Disconnect event.
If this is called from a server, then the connection will be closed without any notice to the client.
Unfortunately this seems to be true
and there is no practical way for the client
to know if the server has closed the connection
.
Help wrote:ReceiveNetworkData()
...
If an error occured on the connection (link broken, connection close by the server etc.), 'Result' will be -1.
  • When the server has closed the connection,
    no more network events will be generated by that connection.
  • If you use ReceiveNetworkData() without a NetworkClientEvent(),
    the program will hang there forever!
The first attempt to send anything (Length > 0 is required to count for that example)
after the server closed the connection, using SendNetworkData() will say, that all was sent!

Only at the second attempt sending something will SendNetworkData() return -1.

Trying to send "something" would not even be a practical way to find out if there still is a connection anyways.

The problem is,
  • Many [HTTP/1.0] servers do close the connection to show,
    that their response data is complete.
    (Do not send a content length or chunked data.)
Our only option to find the end of such a response is:
  • Wait until there is no more NetworkClientEvent()
    and assume, it means the server has closed the connection
    and we therefore got all of the response data.
If there was a way to know, if the server closed the connection,
we would not need such a ugly and unreliable "solution".