开发者

C# handle force closed socket connection

开发者 https://www.devze.com 2023-02-14 02:07 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消