Detect a socket close by remote host in C# .NET

buschmeyerp

Newcomer
Joined
Feb 5, 2004
Messages
3
Location
St. Louis
Is there a way to detect if a socket has been closed by the remote host in C#? I used the .NET Socket class and need to create a delegate and event to notify the main app that the socket connection has been overtly closed.

Currently, the socket in question will throw an exception on the SECOND write after the socket has been closed. This is not robust enough, I need to know that the remote host has closed the socket when it happens (to notify the user!).

The exception is acceptable in the case where the network connection has been corrupted (the socket not closed by the host, but perhaps the network cable has been disconnected), but not for a clean close by a remote host.
 
Back
Top