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);
}
}