views:

120

answers:

1

Hi there,

A SocketException error is thrown when a client disconnects through Read/Write/Accept operations.

When a SocketException is thrown I would love to have details about that 'Client' socket --

namely the Socket.RemoteEndPoint

Any way of getting this from the SocketException object?

I am particulary interested in obtaining request details from the BeginAccept/EndAccept routines.

private Socket _listeningSocket;
// _listeningSocket.Bind().Listen()._BeginAccept().etc

public static void _BeginAccept()
{
    _listeningSocket.BeginAccept(new new AsyncCallback(_EndAccept),null);
}

public static void _EndAccept(IAsyncResult ar)
{
    try
    {
        Socket acceptedSocket = _listeningSocket.EndAccept(ar);
        Process(acceptedSocket);
    }
    catch(SocketException se)
    {
        /////////////////////////////////////////////////
        // Who tried to connect to my _listeningSocket!!!
        /////////////////////////////////////////////////
    }
    finally
    {
        _BeginAccept()
    }
}
A: 

I don't think that's possible via SocketException.

But if you have try-catch well designed, it would not be hard to get Socket.RemoteEndPoint from elsewhere, such as the Socket object you use.

Lex Li
thanks for your reply lextm :) please have a look at the above example
divinci
Just notice this is for Accept. Well, don't have any idea. :) See if others have suggestions.
Lex Li