Main Site Documentation

What scenarios will cause the Socket.Recieve throw an exception?


#1

Using ethernetJ11d, and EthernetBuiltin when running the following code


while(true)
{
_socketReceiver.ReceiveFrom(data, ref endPoint);
//some code here
}

the receive will throw an exception for example when the cable is disconnected.
I can handle this by checking the EthernetBuiltIn .IsCableConnected with and autoResetEvent waiting when detecting that the cable is disconnected and set when cable is reconnected.
the question is what else can cause the receive to throw an exception?


#2

The good place to look is SDK documentation. Each method description page lists what kind of exceptions are thrown by the method.


#3

Well, looks like socket related docs don’t list the exceptions. I would go through the list of socket error codes. These are thrown as SocketExceptions by a socket during its lifetime.

http://msdn.microsoft.com/en-us/library/hh400179.aspx


#4

thanks!
the question is if there’s any indication before running through a loop of exceptions as the cable connected.
since in a regular error I’d like to stop the app but in a legal setup - as cable disconnected I’d like to properly handle it…
so the question is regarding the EthernetBuiltIn if there are any other parameters which can indicate this?


#5

Unfortunately an exception is all you got. Just catch it check the socket error inside the exception and deal with it according with your application logic. There is really nothing else.


#6

@ Devloper123 -

Socket error code can be found at

http://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx

Link does not work from here?
But works from browser… At least fo me…