From 22813bb741a3bf8228b5cfd8e25a8b8e23c8310a Mon Sep 17 00:00:00 2001 From: Gaspard Kirira Date: Sun, 1 Feb 2026 00:14:21 +0300 Subject: [PATCH] docs(readme): update for v1.25.2 --- README.md | 65 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index f7709f4..79ee7a2 100644 --- a/README.md +++ b/README.md @@ -116,30 +116,69 @@ int main() { ### Minimal WebSocket server ```cpp +#include +#include #include -using vix::websocket::Server; - int main() { - Server ws; + vix::config::Config cfg{"config/config.json"}; + + auto exec = vix::experimental::make_threadpool_executor(1, 1, 0); + vix::websocket::Server ws(cfg, std::move(exec)); - ws.on_open([](auto& session) { - session.send_json("chat.system", {"text", "Welcome"}); + ws.on_typed_message([&ws](auto &, const std::string &type, const vix::json::kvs &payload){ + if (type == "chat.message") + ws.broadcast_json("chat.message", payload); }); - ws.on_typed_message( - [](auto& session, - const std::string& type, - const vix::json::kvs& payload){ - (void)session; + ws.listen_blocking(); +} +``` - if (type == "chat.message") { - session.broadcast_json("chat.message", payload); +### config/config.json +```json +{ + "database": { + "default": { + "ENGINE": "mysql", + "NAME": "mydb", + "USER": "myuser", + "PASSWORD": "", + "HOST": "localhost", + "PORT": 3306 } + }, + "server": { + "port": 8080, + "request_timeout": 5000 + }, + "websocket": { + "port": 9090, + "max_message_size": 65536, + "idle_timeout": 600, + "ping_interval": 30, + "enable_deflate": true, + "auto_ping_pong": true + } +} +``` + +### Client.cpp +```cpp +#include +#include +#include + +int main() +{ + auto c = vix::websocket::Client::create("127.0.0.1", "9090", "/"); + c->on_open([c](){ + c->send("chat.message", {"text", "hello"}); }); + c->connect(); - ws.listen_blocking(); + std::this_thread::sleep_for(std::chrono::seconds(5)); } ```