From ca8d6202688427359202410992c90b9146285462 Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Sat, 26 Nov 2022 07:36:01 +0100 Subject: [PATCH] Add some initial client stuff --- build.c | 2 +- examples/Client.cpp | 16 ++++++++++++++++ src/Client.h | 28 ++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 examples/Client.cpp create mode 100644 src/Client.h diff --git a/build.c b/build.c index cbf42d3..1c43c63 100644 --- a/build.c +++ b/build.c @@ -9,7 +9,7 @@ int main(int argc, char **argv) { char *CXX = strcpy(calloc(1024, 1), or_else(getenv("CXX"), "g++")); char *EXEC_SUFFIX = strcpy(calloc(1024, 1), maybe(getenv("EXEC_SUFFIX"))); - char *EXAMPLE_FILES[] = {"Http3Server", "Broadcast", "HelloWorld", "Crc32", "ServerName", + char *EXAMPLE_FILES[] = {"Client", "Http3Server", "Broadcast", "HelloWorld", "Crc32", "ServerName", "EchoServer", "BroadcastingEchoServer", "UpgradeSync", "UpgradeAsync"}; strcat(CXXFLAGS, " -O3 -Wpedantic -Wall -Wextra -Wsign-conversion -Wconversion -std=c++2a -Isrc -IuSockets/src"); diff --git a/examples/Client.cpp b/examples/Client.cpp new file mode 100644 index 0000000..d5f3f4f --- /dev/null +++ b/examples/Client.cpp @@ -0,0 +1,16 @@ +#include "Client.h" +#include + +int main() { + uWS::Client({ + .open = [](/*auto *ws*/) { + std::cout << "Hello and welcome to client" << std::endl; + }, + .message = [](/*auto *ws, auto message*/) { + + }, + .close = [](/*auto *ws*/) { + std::cout << "bye" << std::endl; + } + }).connect("ws://localhost:3000").run(); +} \ No newline at end of file diff --git a/src/Client.h b/src/Client.h new file mode 100644 index 0000000..0fe6df4 --- /dev/null +++ b/src/Client.h @@ -0,0 +1,28 @@ +#include "MoveOnlyFunction.h" + +namespace uWS { + + struct WebSocketClientBehavior { + MoveOnlyFunction open; + MoveOnlyFunction message; + MoveOnlyFunction close; + }; + + struct Client { + + Client(WebSocketClientBehavior &&behavior) { + + } + + Client &&connect(std::string url) { + + return std::move(*this); + } + + void run() { + + } + + }; + +} \ No newline at end of file