Let's say my client appl开发者_如何学运维ication looses connection with server application because of internet problems, the Server then receives a "An existing connection was forcibly closed by the remote host" exception.
What's the proper way to catch this exception, close the server-side socket and then remove it?
this largely depends on what class you're using to establish and maintain the connection.
I typically use TcpClient, TcpListener and their asynchronous functions. When error occurs, the callback function is called with e.Error != null. What usually follows is the removal of the socket, which is conveniently available in e.UserState, from the list of active connections.
精彩评论