From 2a1fc55b5811c31302917af2ff874ec235b4fc2a Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Fri, 21 Dec 2018 03:17:15 +0100 Subject: [PATCH] Add EchoServer example --- Makefile | 6 ++++++ examples/EchoServer.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 examples/EchoServer.cpp diff --git a/Makefile b/Makefile index 9e40bc6..a1688b4 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,12 @@ examples: clang++ -flto -O3 -s *.o -o HelloWorld rm *.o +# EchoServer + clang -flto -O3 -c -IuSockets/src uSockets/src/*.c uSockets/src/eventing/*.c + clang++ -flto -O3 -c -std=c++17 -Isrc -IuSockets/src examples/EchoServer.cpp + clang++ -flto -O3 -s *.o -o EchoServer -lz + rm *.o + # HttpServer (currently quire broken, mind you) clang -flto -O3 -c -IuSockets/src uSockets/src/*.c uSockets/src/eventing/*.c clang++ -flto -O3 -c -std=c++17 -Isrc -IuSockets/src examples/HttpServer.cpp diff --git a/examples/EchoServer.cpp b/examples/EchoServer.cpp new file mode 100644 index 0000000..0df38cd --- /dev/null +++ b/examples/EchoServer.cpp @@ -0,0 +1,32 @@ +#include "App.h" + +int main() { + /* Very simple WebSocket echo server */ + uWS::App().ws("/*", { + /*.compression = */true, + /*.maxPayloadLength*/ + + /*.open = */[](auto *ws, auto *req) { + + }, + /*.message = */[](auto *ws, std::string_view message, uWS::OpCode opCode) { + ws->send(message, opCode); + } + /*.drain = []() { + + }, + .ping = []() { + + }, + .pong = []() { + + }, + .close = []() { + + }*/ + }).listen(9001, [](auto *token) { + if (token) { + std::cout << "Listening on port " << 9001 << std::endl; + } + }).run(); +}