netDumbster.smtp.SimpleSmtpServer.StartListening C# (CSharp) Method

StartListening() private method

Starts the Server
private StartListening ( ) : void
return void
        internal void StartListening()
        {
            this.log.Info("Starting Smtp server");

            IPEndPoint endPoint = new IPEndPoint(this.Configuration.IPAddress, this.Configuration.Port);
            this.tcpListener = new TcpListener(endPoint);

            // Fix the problem with the scenario if the server is stopped, and then
            // restarted with the same port, it will not throw an error.
            this.tcpListener.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            this.tcpListener.Start();

            this.log.DebugFormat("Started Tcp Listener at port {0}", this.Configuration.Port);

            try
            {
                this.log.Debug("Calling BeginAcceptSocket.");
                this.tcpListener.BeginAcceptSocket(new AsyncCallback(this._SocketHandler), this.tcpListener);
                this.log.Debug("BeginAcceptSocket called.");
                this.ServerReady.Set();
            }
            catch (Exception ex)
            {
                this.log.Warn("Unexpected Exception starting the SmtpServer.", ex);
            }
        }

Usage Example

Example #1
0
        internal static SimpleSmtpServer Start(Configuration configuration)
        {
            var server = new SimpleSmtpServer(configuration);

            server.StartListening();
            server.ServerReady.WaitOne();
            return(server);
        }