Aselia.Server.OnBeginAcceptTcpClient C# (CSharp) Method

OnBeginAcceptTcpClient() private method

private OnBeginAcceptTcpClient ( IAsyncResult ar ) : void
ar IAsyncResult
return void
        private void OnBeginAcceptTcpClient(IAsyncResult ar)
        {
            if (Unloaded)
            {
                return;
            }

            ListenerInfo info = (ListenerInfo)ar.AsyncState;
            try
            {
                if (!info.Listener.Server.IsBound)
                {
                    Bind(info, true);
                    return;
                }
                if (Unloaded) // Check a second time because there's some delay.
                {
                    return;
                }
                TcpClient client = info.Listener.EndAcceptTcpClient(ar);

                try
                {
                    switch (info.Binding.Protocol)
                    {
                    case Protocols.Rfc2812:
                    case Protocols.Rfc2812Ssl:
                        Console.WriteLine("Client connecting from {0}.", client.Client.RemoteEndPoint);
                        AcceptClient(client, info);
                        break;

                    case Protocols.InterServer:
                        Console.WriteLine("Client connecting from {0}.", client.Client.RemoteEndPoint);
                        AcceptServer(client, info);
                        break;

                    default:
                        client.Close();
                        break;
                    }
                }
                catch
                {
                    client.Close();
                }

                info.Listener.BeginAcceptTcpClient(OnBeginAcceptTcpClient, info);
            }
            catch
            {
                Bind(info, true);
            }
        }