Untitled
By: a guest | Feb 9th, 2010 | Syntax:
None | Size: 1.11 KB | Hits: 28 | Expires: Never
public class Server
{
private static HttpListener http_server;
private static int port = 8805;
private static ManualResetEvent wait_for_quit = new ManualResetEvent (false);
private static Server server = new Server ();
public static void Main (string[] args)
{
http_server = new HttpListener ();
http_server.Prefixes.Add (string.Format ("http://*:{0}/", port));
http_server.Start ();
http_server.BeginGetContext (ListenerCallback, null);
wait_for_quit.WaitOne ();
}
public static void ListenerCallback (IAsyncResult result)
{
Console.WriteLine ("GotCallback");
HttpListener listener = (HttpListener)result.AsyncState;
// Call EndGetContext to complete the asynchronous operation.
Console.WriteLine ("Calling EndGetContext");
// *** HANGS HERE ***
HttpListenerContext context = listener.EndGetContext (result);
Console.WriteLine ("GotContext");
HttpListenerRequest request = context.Request;
Console.WriteLine ("GotRequest");
// Listen for the next request
listener.BeginGetContext (ListenerCallback, null);
RouteRequest (context);
}
}