Way to determine if Server closed the connection
Posted: Wed Feb 09, 2011 6:07 pm
Unfortunately this seems to be trueHelp 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.
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!
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.)
- 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.
we would not need such a ugly and unreliable "solution".