Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Feb 9th, 2010 | Syntax: None | Size: 1.11 KB | Hits: 28 | Expires: Never
Copy text to clipboard
  1. public class Server
  2. {
  3.         private static HttpListener http_server;
  4.         private static int port = 8805;
  5.  
  6.         private static ManualResetEvent wait_for_quit = new ManualResetEvent (false);
  7.         private static Server server = new Server ();
  8.  
  9.         public static void Main (string[] args)
  10.         {
  11.                 http_server = new HttpListener ();
  12.                 http_server.Prefixes.Add (string.Format ("http://*:{0}/", port));
  13.                 http_server.Start ();
  14.  
  15.                 http_server.BeginGetContext (ListenerCallback, null);
  16.  
  17.                 wait_for_quit.WaitOne ();
  18.         }
  19.  
  20.         public static void ListenerCallback (IAsyncResult result)
  21.         {
  22.                 Console.WriteLine ("GotCallback");
  23.  
  24.                 HttpListener listener = (HttpListener)result.AsyncState;
  25.  
  26.                 // Call EndGetContext to complete the asynchronous operation.
  27.                 Console.WriteLine ("Calling EndGetContext");
  28.  
  29.                 // *** HANGS HERE ***
  30.                 HttpListenerContext context = listener.EndGetContext (result);
  31.  
  32.  
  33.                 Console.WriteLine ("GotContext");
  34.                 HttpListenerRequest request = context.Request;
  35.                 Console.WriteLine ("GotRequest");
  36.  
  37.  
  38.                 // Listen for the next request
  39.                 listener.BeginGetContext (ListenerCallback, null);
  40.  
  41.                 RouteRequest (context);
  42.         }
  43. }