PDA

View Full Version : Detect when a TCP Server dies



jimroos
3rd July 2007, 22:24
I'm using a QTcpSocket to establish a connection with distant tcp servers. Can anyone give me an idea as to how I can tell if the server suddenly goes away? I'm not receiving any disconnect messages from the distant end and I can't be sure they will close the socket properly.

wysota
3rd July 2007, 23:40
You can just try sending some data. If the other side is dead, you won't receive acknowledgements and the socket will timeout with error. Another way is to set the keep-alive option on the socket. This way the tcp/ip stack will ping the other side from time to time and terminate the connection if it doesn't respond.