LC Larsen
September 3rd, 2006, 04:46 PM
Hi,
I'm developing a client server application in .NET 2.0. I'm using asynchronous sockets for the first time. One requirement is that the server must be able to detect if the connection to a client is lost, in which case it should shutdown and close the socket and start listening on the dedicated port again. I have implemented a link-alive solution in order to detect if link is lost. This all works fine if the client closes the connection nicely, but if I suddenly pull the network cable, and after some time attaches it again, the new socket connection will suddenly stop receiving data (my delegate isn't being called).
I suspect the problem arises because I am not closing the old connection correctly. So my question is this, what is the proper way to close a asynchronous socket connection in case network access is suddenly lost? In this case, the receive data delegate is called and I get a SocketException telling me that the Remote host was forcibly closed or something like that.
Thank you very much.
I'm developing a client server application in .NET 2.0. I'm using asynchronous sockets for the first time. One requirement is that the server must be able to detect if the connection to a client is lost, in which case it should shutdown and close the socket and start listening on the dedicated port again. I have implemented a link-alive solution in order to detect if link is lost. This all works fine if the client closes the connection nicely, but if I suddenly pull the network cable, and after some time attaches it again, the new socket connection will suddenly stop receiving data (my delegate isn't being called).
I suspect the problem arises because I am not closing the old connection correctly. So my question is this, what is the proper way to close a asynchronous socket connection in case network access is suddenly lost? In this case, the receive data delegate is called and I get a SocketException telling me that the Remote host was forcibly closed or something like that.
Thank you very much.