项目作者: v0l

项目描述 :
Asynchronous Http Web Server
高级语言: C#
项目地址: git://github.com/v0l/ahws.git
创建时间: 2017-09-06T15:49:15Z
项目社区:https://github.com/v0l/ahws

开源协议:MIT License

下载


AHWS

Async Http Web Server

Simple to use Async webserver with websocket support

Example Http Server

  1. HttpServer s = new HttpServer(8080);
  2. s.OnLog += Console.WriteLine;
  3. s.Options = HttpServerOptions.GZip | HttpServerOptions.KeepAlive;
  4. s.AddRoute("/", (h) => {
  5. var rsp = h.Request.CreateResponse(HttpStatus.OK);
  6. rsp.Content = new HttpContent(Encoding.UTF8.GetBytes("<h1>Hello world!</h1>"));
  7. rsp.Headers.ContentType = "text/html";
  8. return rsp;
  9. });
  10. s.Start();

Example Websocket Echo

  1. HttpServer s = new HttpServer(8080);
  2. WebsocketServer ws = new WebsocketServer();
  3. ws.OnWebsocketConnect += (w) =>
  4. {
  5. w.OnFrame += async (f) =>
  6. {
  7. //send the frame back
  8. await f.WebSocket.SendFrame(f.Frame);
  9. };
  10. w.Start();
  11. };
  12. s.OnLog += Console.WriteLine;
  13. s.Options = HttpServerOptions.GZip | HttpServerOptions.KeepAlive;
  14. s.AddRoute("/ws", ws.WebsocketUpgrade);
  15. s.Start();