Add EchoServer example

This commit is contained in:
Alex Hultman
2018-12-21 03:17:15 +01:00
parent 3e75936387
commit 2a1fc55b58
2 changed files with 38 additions and 0 deletions
+6
View File
@@ -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
+32
View File
@@ -0,0 +1,32 @@
#include "App.h"
int main() {
/* Very simple WebSocket echo server */
uWS::App().ws<void>("/*", {
/*.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();
}