/// <summary>
 /// Initializes a new instance of the HttpConnection class (Clients use this contructor)
 /// </summary>
 public HttpConnection(bool verbose)
 {
     _verbose       = verbose;
     _id            = Guid.NewGuid();
     _dispatcher    = new HttpRequestDispatcher(false);
     _messageWriter = new HttpMessageWriter();
     _messageReader = new HttpMessageReader();
 }
        /// <summary>
        /// Initializes a new instance of the HttpConnection class (Servers use this constructor)
        /// </summary>
        /// <param name="socket">The socket to be used for the lifetime of the connection</param>
        public HttpConnection(Socket socket, bool verbose)
        {
            if (socket == null)
            {
                throw new ArgumentNullException("socket", "A connection cannot be created using a null socket.");
            }

            _verbose       = verbose;
            _socket        = socket;
            _id            = Guid.NewGuid();
            _dispatcher    = new HttpRequestDispatcher(false);
            _messageWriter = new HttpMessageWriter();
            _messageReader = new HttpMessageReader();
        }
        public HttpConnection(IPEndPoint ep, bool beginReceiving, bool verbose, int sendTimeout, int recvTimeout)
        {
            if (ep == null)
            {
                throw new ArgumentNullException("ep");
            }

            _verbose       = verbose;
            _id            = Guid.NewGuid();
            _dispatcher    = new HttpRequestDispatcher(false);
            _messageWriter = new HttpMessageWriter();
            _messageReader = new HttpMessageReader();

            this.Open(ep, beginReceiving, sendTimeout, recvTimeout);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Stops the server (No incoming connections will be accepted while the server is stopped)
        /// </summary>
        /// <returns></returns>
        public bool Stop(bool endCurrentSessions)
        {
            try
            {
                if (endCurrentSessions)
                {
                    this.EndCurrentSessions();
                }

                if (_thread != null)
                {
                    _thread.Dispose();
                    _thread = null;
                }

                if (_listeningSocket != null)
                {
                    try
                    {
                        // shutdown and close the socket
                        //             _socket.Shutdown(SocketShutdown.Both);
                        _listeningSocket.Close();
                    }
                    catch (SocketException ex)
                    {
                        Debug.WriteLineIf(_verbose, string.Format("An exception was encountered while attempting to shutdown & close the server's listening socket.\n\t{0}", ex.ToString()), TraceCategory);
                    }
                    _listeningSocket = null;
                }

                _isStarted  = false;
                _dispatcher = null;

                EventManager.Raise <EventArgs>(this.ServerStopped, this, EventArgs.Empty);

                return(true);
            }
            catch (Exception ex)
            {
                this.OnException(this, new ExceptionEventArgs(ex));
            }
            return(false);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Starts the server.  Optionally enabling Asp.NET hosting if the host OS supports it.
        /// </summary>
        /// <param name="ep"></param>
        /// <param name="enableAspNetHosting"></param>
        /// <returns></returns>
        public bool Start(IPEndPoint ep, bool enableAspNetHosting)
        {
            try
            {
                _dispatcher = new HttpRequestDispatcher(enableAspNetHosting && this.CanOSSupportAspNet);

                _thread      = new BackgroundThread();
                _thread.Run += new BackgroundThreadStartEventHandler(OnThreadRun);
                _thread.Start(true, new object[] { ep });
                _isStarted = true;

                EventManager.Raise <EventArgs>(this.ServerStarted, this, EventArgs.Empty);

                return(true);
            }
            catch (Exception ex)
            {
                this.OnException(this, new ExceptionEventArgs(ex));
            }
            return(false);
        }
Ejemplo n.º 6
0
		/// <summary>
		/// Stops the server (No incoming connections will be accepted while the server is stopped)
		/// </summary>
		/// <returns></returns>
		public bool Stop(bool endCurrentSessions)
		{
			try
			{                       
				if (endCurrentSessions)
					this.EndCurrentSessions();

				if (_thread != null)
				{
					_thread.Dispose();
					_thread = null;
				}

				if (_listeningSocket != null)
				{
					try 
					{
						// shutdown and close the socket
						//             _socket.Shutdown(SocketShutdown.Both);
						_listeningSocket.Close();
					}
					catch(SocketException ex) 
					{
						Debug.WriteLineIf(_verbose, string.Format("An exception was encountered while attempting to shutdown & close the server's listening socket.\n\t{0}", ex.ToString()), TraceCategory);
					}
					_listeningSocket = null;
				}

				_isStarted = false;
				_dispatcher = null;

				EventManager.Raise<EventArgs>(this.ServerStopped, this, EventArgs.Empty);

				return true;
			}
			catch(Exception ex)
			{
				this.OnException(this, new ExceptionEventArgs(ex));
			}        
			return false;
		}
Ejemplo n.º 7
0
		/// <summary>
		/// Starts the server.  Optionally enabling Asp.NET hosting if the host OS supports it.
		/// </summary>
		/// <param name="ep"></param>
		/// <param name="enableAspNetHosting"></param>
		/// <returns></returns>
		public bool Start(IPEndPoint ep, bool enableAspNetHosting)
		{
			try
			{
				_dispatcher = new HttpRequestDispatcher(enableAspNetHosting && this.CanOSSupportAspNet);

				_thread = new BackgroundThread();
				_thread.Run += new BackgroundThreadStartEventHandler(OnThreadRun);
				_thread.Start(true, new object[] { ep });
				_isStarted = true;

				EventManager.Raise<EventArgs>(this.ServerStarted, this, EventArgs.Empty);

				return true;
			}
			catch (Exception ex)
			{
				this.OnException(this, new ExceptionEventArgs(ex));
			}
			return false;
		}
		/// <summary>
		/// Initializes a new instance of the HttpConnection class (Servers use this constructor)
		/// </summary>
		/// <param name="socket">The socket to be used for the lifetime of the connection</param>
		public HttpConnection(Socket socket, bool verbose) 
		{
			if (socket == null)
				throw new ArgumentNullException("socket", "A connection cannot be created using a null socket.");

			_verbose = verbose;
			_socket = socket;
			_id = Guid.NewGuid();				
			_dispatcher = new HttpRequestDispatcher(false);
			_messageWriter = new HttpMessageWriter();	
			_messageReader = new HttpMessageReader();
		}
		public HttpConnection(IPEndPoint ep, bool beginReceiving, bool verbose, int sendTimeout, int recvTimeout)
		{
			if (ep == null)
				throw new ArgumentNullException("ep");

			_verbose = verbose;			
			_id = Guid.NewGuid();				
			_dispatcher = new HttpRequestDispatcher(false);
			_messageWriter = new HttpMessageWriter();	
			_messageReader = new HttpMessageReader();

			this.Open(ep, beginReceiving, sendTimeout, recvTimeout);
		}
Ejemplo n.º 10
0
		/// <summary>
		/// Initializes a new instance of the HttpConnection class (Clients use this contructor)
		/// </summary>
		public HttpConnection(bool verbose) 
		{
			_verbose = verbose;
			_id = Guid.NewGuid();	
			_dispatcher = new HttpRequestDispatcher(false);
			_messageWriter = new HttpMessageWriter();
			_messageReader = new HttpMessageReader();
		}