private static string Listen(HttpListener listener) { if (listener.IsListening) { Console.WriteLine("Listening..."); } var context = listener.GetContext(); var request = context.Request; if (request != null) { Console.WriteLine("Got a request"); } else { throw new NetworkInformationException(); } context.Response.StatusCode = 200; var reader = new Program.MessageReader(request.InputStream); reader.ReadMessage(); context.Response.Close(); return(reader.Body); }
public void ListenerCallback(IAsyncResult result) { HttpListener listener = (HttpListener)result.AsyncState; HttpListenerContext context = listener.EndGetContext(result); HttpListenerRequest request = context.Request; HttpListenerResponse response = context.Response; response.StatusCode = 200; var reader = new Program.MessageReader(request.InputStream); reader.ReadMessage(); BuildandAddUsers(reader.Body, CurrentMessage); response.Close(); var nextIteration = listener.BeginGetContext(ListenerCallback, listener); }