AsyncSocketSample.Server.StartAccept C# (CSharp) Method

StartAccept() public method

Begins an operation to accept a connection request from the client
public StartAccept ( SocketAsyncEventArgs acceptEventArg ) : void
acceptEventArg System.Net.Sockets.SocketAsyncEventArgs The context object to use when issuing the accept operation on the /// server's listening socket
return void
        public void StartAccept(SocketAsyncEventArgs acceptEventArg)
        {
            if (acceptEventArg == null)
            {
                acceptEventArg = new SocketAsyncEventArgs();
                acceptEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(AcceptEventArg_Completed);
            }
            else
            {
                // socket must be cleared since the context object is being reused
                acceptEventArg.AcceptSocket = null;
            }

            m_maxNumberAcceptedClients.WaitOne();
            bool willRaiseEvent = listenSocket.AcceptAsync(acceptEventArg);
            if (!willRaiseEvent)
            {
                ProcessAccept(acceptEventArg);
            }
        }