示例#1
0
 /// <summary>
 /// Begins listening HTTP requests
 /// </summary>
 public void Start()
 {
     _listener = new TcpListener(IPAddress.Any, Port);
     _listener.Start();
     new Thread(delegate()
     {
         Thread.CurrentThread.Name = "WebServer";
         while (_listener != null)
         {
             _listener.BeginAcceptTcpClient(delegate(IAsyncResult result)
             {
                 try
                 {
                     var client =
                         _listener.EndAcceptTcpClient(result);
                     _autoReset.Set();
                     var ea =
                         new WebServerConnectedEventArgs(client);
                     OnConnected(ea);
                     if (!ea.Handled)
                     {
                         var ns          = client.GetStream();
                         ns.ReadTimeout  = 15 * 1000;
                         ns.WriteTimeout = 60 * 1000 * 5;
                         var req         = new Request(ns);
                         var resp        = new Response(ns);
                         var rea         =
                             new WebServerRequestEventArgs(
                                 req, resp);
                         OnRequest(rea);
                         resp.Close();
                         client.Close();
                     }
                 }
                 catch (ObjectDisposedException)
                 {
                 }
                 catch (NullReferenceException)
                 {
                 }
             }, null);
             _autoReset.WaitOne();
         }
     }).Start();
 }
示例#2
0
 protected void OnRequest(WebServerRequestEventArgs e)
 {
     Request?.Invoke(this, e);
 }