Example #1
0
File: MEH.cs Project: josip/meh
        private void InvokeResponseHandler(Dictionary<string, ResponseHandler> dict, HttpProcessor p)
        {
            foreach(KeyValuePair<string, ResponseHandler> pair in dict) {
            Match match = Regex.Match(p.http_path, pair.Key);
            if(match.Success) {
              try {
            pair.Value.Invoke(match.Groups, p);
              } catch {
            p.Respond(HttpStatusCode.InternalServerError, "Internal server error.");
              }
              return;
            }
              }

              p.Respond(HttpStatusCode.NotFound, "There's nothing here!");
        }
Example #2
0
File: MEH.cs Project: josip/meh
 internal void HandleGETRequest(HttpProcessor p)
 {
     InvokeResponseHandler(getUrlMap, p);
 }
Example #3
0
File: MEH.cs Project: josip/meh
 internal void HandlePOSTRequest(HttpProcessor p)
 {
     InvokeResponseHandler(postUrlMap, p);
 }
Example #4
0
File: MEH.cs Project: josip/meh
 /// <summary>
 /// Starts the server.
 /// 
 /// Example usage:
 ///     class MyServer : HttpServer {}
 ///     ...
 ///     MyServer server = new MyServer(8080);
 ///     Thread serverThread = new Thread(new ThreadStarted(server.Listen));
 ///     serverThread.Start();
 /// </summary>
 public void Listen()
 {
     listener = new TcpListener(System.Net.IPAddress.Any, port);
       listener.Start();
       while(is_active) {
     TcpClient s = listener.AcceptTcpClient();
     HttpProcessor processor = new HttpProcessor(s, this);
     Thread thread = new Thread(new ThreadStart(processor.Process));
     thread.Start();
     Thread.Sleep(1);
       }
 }