static async void ProcessRequest() { int count = 0; var settings = new WebListenerSettings(); settings.UrlPrefixes.Add("http://localhost:9000"); using (WebListener listener = new WebListener(settings)) { listener.Start(); while (true) { var context = await listener.AcceptAsync(); byte[] bytes = Encoding.ASCII.GetBytes( "ConnectionId" + context.Request.ToString() + "\nHeaders" + context.Request.Headers + "\n" + DateTime.Now); context.Response.ContentLength = bytes.Length; context.Response.ContentType = "text/plain"; await context.Response.Body.WriteAsync(bytes, 0, bytes.Length); context.Dispose(); Console.WriteLine("Request==>{0}", ++count); } } }
public WebServer(WebServerInterface serverInterface) { if (!HyperTextDocumentsExists()) { return; } ServerInterface = serverInterface; webListener = new WebListener($"http://*:{ServerInterface.GetPortNumber()}/"); webListener.HttpCall += WebListener_HttpCall; webListener.WebServerStarted += WebListener_WebServerStarted; webListener.WebServerStopped += WebListener_WebServerStopped; foreach (var file in Directory.GetFiles("HyperTextDocuments")) { FileInfo fileInfo = new FileInfo(file); ServerInterface.Invoke(new MethodInvoker(() => ServerInterface.UpdateFileLayout(fileInfo.Name, fileInfo.FullName))); } WatchFiles(); }