public void Dispose()
 {
     if (socket != null && socket.Connected)
     {
         socket.Disconnect(true);
     }
     socket    = null;
     processor = null;
 }
 /// <summary>
 /// Create a ConnectionWrapper to allow for a thread start.
 /// </summary>
 /// <param name="processor"></param>
 /// <param name="socket"></param>
 public ConnectionWrapper(ConnectionProcessor processor, Socket socket)
 {
     _processor = processor;
     _socket = socket;
 }
Example #3
0
        public void Run()
        {
            Trace.TraceInformation("Server started on port: " + _server.Port);
            while (!IsStopped())
            {
                try
                {
                    TcpClient connection = null;
                    Stream stream = null;
                    try
                    {
                        connection = _socket.AcceptTcpClient();
                        stream = connection.GetStream();
                        if (_server.UseSSL)
                        {
                            SslStream sslStream = new SslStream(stream, false);
                            stream = sslStream;
                            sslStream.AuthenticateAsServer(_server.ServerCertificate,
                                                           false,
                                                           SslProtocols.Tls,
                                                           false);
                        }

                        ConnectionProcessor processor =
                            new ConnectionProcessor(_server,
                                                    new RemoteFrameworkConnection(connection, stream));
                        Thread thread = new Thread(processor.Run);
                        thread.IsBackground = false;
                        thread.Start();
                    }
                    catch (Exception)
                    {
                        if (stream != null)
                        {
                            try { stream.Close(); }
                            catch (Exception) { }
                        }
                        if (connection != null)
                        {
                            try { connection.Close(); }
                            catch (Exception) { }
                        }
                        throw;
                    }
                }
                catch (Exception e)
                {
                    //log the error unless it's because we've stopped
                    if (!IsStopped() || !(e is SocketException))
                    {
                        TraceUtil.TraceException("Error processing request", e);
                    }
                    //wait a second before trying again
                    if (!IsStopped())
                    {
                        Thread.Sleep(1000);
                    }
                }
            }
        }
		//private static ILog log = LogManager.GetLogger( typeof( SimpleSMTPServer ) );
		
		#endregion
				
		#region Constructors
		
		/// <summary>
		/// Creates a new SimpleSMTPServer that listens on a specific
		/// port for connections and passes them to the specified delagat
		/// </summary>
		/// <param name="port">The port to listen on.</param>
		/// <param name="processor">The ConnectionProcessor that will handle the incoming connections.</param>
		public SimpleSMTPServer( int port, ConnectionProcessor processor )
		{
			this.port = port;
			this.processor = processor;
		}
		/// <summary>
		/// Create a ConnectionWrapper to allow for a thread start.
		/// </summary>
		/// <param name="processor"></param>
		/// <param name="socket"></param>
		public ConnectionWrapper( ConnectionProcessor processor, Socket socket )
		{
			this.processor = processor;
			this.socket = socket;
		}
 /// <summary>
 /// Creates a new SimpleServer that listens on a specific
 /// port for connections and passes them to the specified delagat
 /// </summary>
 /// <param name="port">The port to listen on.</param>
 /// <param name="processor">The ConnectionProcessor that will handle the incoming connections.</param>
 public SimpleServer(int port, ConnectionProcessor processor)
 {
     this.port      = port;
     this.processor = processor;
 }
 /// <summary>
 /// Create a ConnectionWrapper to allow for a thread start.
 /// </summary>
 /// <param name="processor"></param>
 /// <param name="socket"></param>
 public ConnectionWrapper(ConnectionProcessor processor, Socket socket)
 {
     this.processor = processor;
     this.socket    = socket;
 }
Example #8
0
 /// <summary>
 /// Creates a new SimpleServer that listens on a specific
 /// port for connections and passes them to the specified delagat
 /// </summary>
 /// <param name="port">The port to listen on.</param>
 /// <param name="processor">The ConnectionProcessor that will handle the incoming connections.</param>
 public SimpleServer(int port, ConnectionProcessor processor)
 {
     _port = port;
     _processor = processor;
 }