How does an asynchronous socket operation work? WITH#

First, I accept async requests for Socket.

if (!_handle.AcceptAsync(_item)) AcceptClient(null, _item);

Handling them like that.

private void AcceptClient(object s, SocketAsyncEventArgs e)
    {
        try
        {
            do
            {
                switch(e.SocketError)
                {
                    case SocketError.Success:
                        // Do something with socket
                        break;

                    case SocketError.ConnectionReset:
                        break;

                    default:
                        throw new Exception("Socket Error");
                }

                e.AcceptSocket = null;
            }
            while (!_handle.AcceptAsync(e));
        }
        catch(ObjectDisposedException)
        {
        }
        catch(Exception)
        {
            Disconnect();
        }
    }

So, when the socket is accepted by async, it cyclically synchronizes. (Immediately processes the following). However, I do not understand a few things here.

How does the processing code work when it allows you to connect 20 clients at the same time? Does AcceptSync return false, and does it need to be processed immediately after the first asynchronous one? Can some be asynchronous and some synchronization in such an instance handle several at the same time?

Is it possible to call multiple callbacks in this situation?

Thank!

+4
source share

No one has answered this question yet.


All Articles