Click to See Complete Forum and Search --> : Detect lost connection to peer


nice_guy_mel
August 14th, 2009, 09:25 AM
I've been experimenting with the using System.Net.Sockets.Socket class for .Net 2.0 in Visual Studio 2005.
I have a server application that accepts TCP connections from client machines. The software that the clients are using is not ours so we can't use any handshaking communications. I want to be able to detect if the network cable connecting the client machine to the network gets disconnected. I first tried the Poll method, but it didn't work. The MSDN actually stated that Poll cannot be used for detecting Network cable failures, and instead to try sending/receiving. Since the server application is ours I added code to send out a small message to the client socket every 5 seconds. I figured once I pulled the network cable at the client machine, the send would throw an exception and I would be able to catch the event. However the send kept sending with no problems at the server end. I already have a thread that performs a receive attempt on the client socket to read in client messages, and that code continues to run as well with no exceptions.
That leaves me kind of stuck. I read in another post about setting up a KEEP_ALIVE option on the socket, but the minimum wait time is 2 hours, which is too long to detect that the client connection is lost.
I'm wondering if anyone else ran into this problem in .Net and found a solution?

nice_guy_mel
August 6th, 2010, 05:48 AM
Still wondering about this issue.