コード例 #1
0
ファイル: SmtpListener.cs プロジェクト: JoeBuntu/Smtp-Server
        private void AcceptClient(IAsyncResult result)
        {
            using(ScopedActivity localActivity = new ScopedActivity("Accepting Client Connection"))
            {
                TcpClient client = null;
                TcpListener listener = (TcpListener)result.AsyncState;

                //this section is critical for the robustness of the application.
                //it should only accept the client and begin accepting new connections
                //in the finally block
                try
                {
                    localActivity.Log("Listener: {0}", listener.LocalEndpoint);
                    client = listener.EndAcceptTcpClient(result);
                }
                catch (Exception ex)
                {
                    localActivity.LogException(ex, "An exception occurred while accepting client connection");
                }
                finally
                {
                    listener.BeginAcceptTcpClient(AcceptClient, listener);
                }

                //if client was successfully accepted, continue the processing chain
                if (client != null)
                {
                    ProcessClient(client, listener, localActivity);
                }
            }
        }
コード例 #2
0
ファイル: SmtpListener.cs プロジェクト: JoeBuntu/Smtp-Server
        public void Start()
        {
            try
            {
                _HasStarted = true;
                _Activity = new ScopedActivity("SmtpListener");

                InitializeListeners();
            }
            catch (Exception ex)
            {
                if (_Activity != null)
                {
                    _Activity.LogException(ex, "Exception Occurred While Starting Smtp Listener");
                }
            }
        }