working on broadcast
This commit is contained in:
Binary file not shown.
+52
-44
@@ -36,51 +36,59 @@ int main()
|
||||
.cert_file_name = "misc/cert.pem",
|
||||
.passphrase = "1234"})
|
||||
.ws<PerSocketData>(
|
||||
"/*", {/* Settings */
|
||||
.compression = uWS::CompressOptions(uWS::DEDICATED_COMPRESSOR_4KB | uWS::DEDICATED_DECOMPRESSOR),
|
||||
.maxPayloadLength = 100 * 1024 * 1024,
|
||||
.idleTimeout = 16,
|
||||
.maxBackpressure = 100 * 1024 * 1024,
|
||||
.closeOnBackpressureLimit = false,
|
||||
.resetIdleTimeoutOnSend = false,
|
||||
.sendPingsAutomatically = true,
|
||||
/* Handlers */
|
||||
.upgrade = nullptr,
|
||||
.open =
|
||||
[](uWS::WebSocket<false, true, PerSocketData> *ws) {
|
||||
auto user_data = ws->getUserData();
|
||||
user_data->created_at = DateTime::now();
|
||||
"/*",
|
||||
{/* Settings */
|
||||
.compression = uWS::CompressOptions(uWS::DEDICATED_COMPRESSOR_4KB | uWS::DEDICATED_DECOMPRESSOR),
|
||||
.maxPayloadLength = 100 * 1024 * 1024,
|
||||
.idleTimeout = 16,
|
||||
.maxBackpressure = 100 * 1024 * 1024,
|
||||
.closeOnBackpressureLimit = false,
|
||||
.resetIdleTimeoutOnSend = false,
|
||||
.sendPingsAutomatically = true,
|
||||
/* Handlers */
|
||||
.upgrade = nullptr,
|
||||
.open =
|
||||
[](uWS::WebSocket<false, true, PerSocketData> *ws) {
|
||||
auto user_data = ws->getUserData();
|
||||
user_data->created_at = DateTime::now();
|
||||
|
||||
DateTime::outputTime("Client connected at ", user_data->created_at);
|
||||
},
|
||||
.message =
|
||||
[](auto *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
|
||||
* the reason we do the opposite here; compress if SMALLER than 16 kb is to allow for
|
||||
* benchmarking of large message sending without compression */
|
||||
std::cout << "Message received: " << message << std::endl;
|
||||
ws->send(message, opCode, message.length() < 16 * 1024);
|
||||
},
|
||||
.dropped =
|
||||
[](auto * /*ws*/, std::string_view /*message*/, uWS::OpCode /*opCode*/) {
|
||||
/* A message was dropped due to set maxBackpressure and closeOnBackpressureLimit limit */
|
||||
},
|
||||
.drain =
|
||||
[](auto * /*ws*/) {
|
||||
/* Check ws->getBufferedAmount() here */
|
||||
},
|
||||
.ping =
|
||||
[](auto * /*ws*/, std::string_view) {
|
||||
/* Not implemented yet */
|
||||
},
|
||||
.pong =
|
||||
[](auto * /*ws*/, std::string_view) {
|
||||
/* Not implemented yet */
|
||||
},
|
||||
.close =
|
||||
[](auto * /*ws*/, int /*code*/, std::string_view /*message*/) {
|
||||
/* You may access ws->getUserData() here */
|
||||
}})
|
||||
DateTime::outputTime("Client connected at ", user_data->created_at);
|
||||
if (!ws->subscribe("*"))
|
||||
{
|
||||
std::cout << "Failed to subscribe to * channel\n";
|
||||
ws->close();
|
||||
}
|
||||
},
|
||||
.message =
|
||||
[](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
|
||||
* the reason we do the opposite here; compress if SMALLER than 16 kb is to allow for
|
||||
* benchmarking of large message sending without compression */
|
||||
std::cout << "Message received: " << message << std::endl;
|
||||
ws->send(message, opCode, false);
|
||||
ws->publish("*", message, opCode, false);
|
||||
},
|
||||
.dropped =
|
||||
[](auto * /*ws*/, std::string_view /*message*/, uWS::OpCode /*opCode*/) {
|
||||
/* A message was dropped due to set maxBackpressure and closeOnBackpressureLimit limit */
|
||||
},
|
||||
.drain =
|
||||
[](auto * /*ws*/) {
|
||||
/* Check ws->getBufferedAmount() here */
|
||||
},
|
||||
.ping =
|
||||
[](auto * /*ws*/, std::string_view) {
|
||||
/* Not implemented yet */
|
||||
},
|
||||
.pong =
|
||||
[](auto * /*ws*/, std::string_view) {
|
||||
/* Not implemented yet */
|
||||
},
|
||||
.close =
|
||||
[](auto * /*ws*/, int /*code*/, std::string_view /*message*/) {
|
||||
/* You may access ws->getUserData() here */
|
||||
std::cout << "Client disconnected\n";
|
||||
}})
|
||||
.listen(9001,
|
||||
[](auto *listen_socket) {
|
||||
if (listen_socket)
|
||||
|
||||
Reference in New Issue
Block a user