views:

660

answers:

1

In my application, I currently stop listening when AcceptTcpClient (or EndAcceptTcpClient) throws an exception. Typically exceptions are thrown when I stop the listener (socket error 10004) or when I disconnect the network adapter.

try
{
    while (true)
    {
        TcpClient client = listener.AcceptTcpClient();
        // omitted: start new thread which handles the client connection
    }
}
catch (...)
{
    // omitted: handle exception, log, stop listening
}

But, are there any exceptions that are caused by the client, and would require to ignore (or log) the exception and continue calling AcceptTcpClient?

A: 

MSDN has documentation that will list all exceptions that can be thrown by methods/members/etc.

I find it easy to get where you want to go by searching google for something like "MSDN Ssystem.Net.Sockets.TcpListener class" and then navigating to the page I need.

TcpLisenter.AcceptTcpClient Method

MSDN lists 2 exceptions that can be thrown.

InvalidOperationException : The listener has not been started with a call to Start.

SocketException : Use the SocketException.ErrorCode property to obtain the specific error code. When you have obtained this code, you can refer to the Windows Sockets version 2 API error code documentation in MSDN for a detailed description of the error.

Chad Moran
I know the documentation, and I have read it throughly. But it does not answer my question.
Stefan Schultze
"Use the SocketException.ErrorCode property to obtain the specific error code."That's a total copout. Thanks for nothing MSDN!
Eric Nicholson