The information below is given on the MSDN article on the Socket.Available
property.
If the remote host shuts down or closes the connection, Available can throw a SocketException.
The keyword here being can. My question is:
Is Socket.Available
just as reliable as Socket.Receive()
to throw a SocketException on disconnect, and more directly, under what circumstances will Socket.Available
not throw a SocketException?
Internally
Available
is calling the native methodioctlsocket
with the commandFIONREAD
, if that function returnsSOCKET_ERROR
then it raises aSocketException
.So to answer your question
Socket.Available
not throw aSocketException
when a call toioctlsocket
could be made without error.