From 63e483b81513b8cc27a331b078f76b0097749ee6 Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Thu, 22 Nov 2018 00:39:40 +0100 Subject: [PATCH] Update demo interface --- README.md | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 53405d0..4c71b45 100644 --- a/README.md +++ b/README.md @@ -17,37 +17,32 @@ uWS::SSLApp({ .cert_file_name = "cert.pem", .key_file_name = "key.pem" -}).onGet("/", [](auto *res, auto *req) { +}).get("/hello", [](auto *res, auto *req) { - /* Respond with the web app on default route */ - res->writeStatus("200 OK") - ->writeHeader("Content-Type", "text/html; charset=utf-8") - ->end(indexHtmlBuffer); + /* You can efficiently stream huge files too */ + res->writeHeader("Content-Type", "text/html; charset=utf-8")->end("Hello HTTP!"); -}).onWebSocket("/ws/chat", [&](auto *ws, auto *req) { +}).ws("/*", { - /* Subscribe to topic /chat */ - ws->subscribe("chat"); - -}).onMessage([&](auto *ws, auto message, auto opCode) { - - /* Parse incoming message according to some protocol & publish it */ - if (seemsReasonable(message)) { - ws->publish("chat", message); - } else { - ws->close(); + /* Just a few of the available handlers */ + .open = [](auto *ws, auto *req) { + ws->subscribe("buzzword weekly"); + }, + .message = [](auto *ws, std::string_view message, uWS::OpCode opCode) { + ws->send(message, opCode); } -}).onClose([&](auto *ws, int code, auto message) { +}).listen(9001, [](auto *token) { - /* Remove websocket from this topic */ - ws->unsubscribe("chat"); + if (token) { + std::cout << "Listening on port " << 9001 << std::endl; + } -}).listen("localhost", 3000, 0).run(); +}).run(); ``` #### Pay what you want. -A free & open source ([Zlib](LICENSE)) project since 2016. Kindly sponsored by [BitMEX](https://bitmex.com), [Bitfinex](https://bitfinex.com) & [Coinbase](https://www.coinbase.com/) in 2018. +A free & open source ([permissive](LICENSE)) project since 2016. Kindly sponsored by [BitMEX](https://bitmex.com), [Bitfinex](https://bitfinex.com) & [Coinbase](https://www.coinbase.com/) in 2018.