working on broadcast

This commit is contained in:
talksik
2024-01-27 12:49:49 -08:00
parent fa9d2a8478
commit 3a63dfbe7b
2 changed files with 52 additions and 44 deletions
+11 -3
View File
@@ -36,7 +36,8 @@ int main()
.cert_file_name = "misc/cert.pem", .cert_file_name = "misc/cert.pem",
.passphrase = "1234"}) .passphrase = "1234"})
.ws<PerSocketData>( .ws<PerSocketData>(
"/*", {/* Settings */ "/*",
{/* Settings */
.compression = uWS::CompressOptions(uWS::DEDICATED_COMPRESSOR_4KB | uWS::DEDICATED_DECOMPRESSOR), .compression = uWS::CompressOptions(uWS::DEDICATED_COMPRESSOR_4KB | uWS::DEDICATED_DECOMPRESSOR),
.maxPayloadLength = 100 * 1024 * 1024, .maxPayloadLength = 100 * 1024 * 1024,
.idleTimeout = 16, .idleTimeout = 16,
@@ -52,14 +53,20 @@ int main()
user_data->created_at = DateTime::now(); user_data->created_at = DateTime::now();
DateTime::outputTime("Client connected at ", user_data->created_at); DateTime::outputTime("Client connected at ", user_data->created_at);
if (!ws->subscribe("*"))
{
std::cout << "Failed to subscribe to * channel\n";
ws->close();
}
}, },
.message = .message =
[](auto *ws, std::string_view message, uWS::OpCode opCode) { [](uWS::WebSocket<false, true, PerSocketData> *ws, std::string_view message, uWS::OpCode opCode) {
/* This is the opposite of what you probably want; compress if message is LARGER than 16 kb /* This is the opposite of what you probably want; compress if message is LARGER than 16 kb
* the reason we do the opposite here; compress if SMALLER than 16 kb is to allow for * the reason we do the opposite here; compress if SMALLER than 16 kb is to allow for
* benchmarking of large message sending without compression */ * benchmarking of large message sending without compression */
std::cout << "Message received: " << message << std::endl; std::cout << "Message received: " << message << std::endl;
ws->send(message, opCode, message.length() < 16 * 1024); ws->send(message, opCode, false);
ws->publish("*", message, opCode, false);
}, },
.dropped = .dropped =
[](auto * /*ws*/, std::string_view /*message*/, uWS::OpCode /*opCode*/) { [](auto * /*ws*/, std::string_view /*message*/, uWS::OpCode /*opCode*/) {
@@ -80,6 +87,7 @@ int main()
.close = .close =
[](auto * /*ws*/, int /*code*/, std::string_view /*message*/) { [](auto * /*ws*/, int /*code*/, std::string_view /*message*/) {
/* You may access ws->getUserData() here */ /* You may access ws->getUserData() here */
std::cout << "Client disconnected\n";
}}) }})
.listen(9001, .listen(9001,
[](auto *listen_socket) { [](auto *listen_socket) {