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.