From b47cb434199f9564494f95cf73775d16a85a1ca3 Mon Sep 17 00:00:00 2001 From: <> Date: Sat, 25 Jul 2020 18:43:04 +0000 Subject: [PATCH] Deployed 847fc14 with MkDocs version: 1.1.2 --- CHANGELOG/index.html | 6 ++++ index.html | 2 +- search/search_index.json | 2 +- sitemap.xml.gz | Bin 198 -> 198 bytes usage/index.html | 63 ++++++++++++++++++++++----------------- 5 files changed, 44 insertions(+), 29 deletions(-) diff --git a/CHANGELOG/index.html b/CHANGELOG/index.html index bfa841fc..30b31045 100644 --- a/CHANGELOG/index.html +++ b/CHANGELOG/index.html @@ -95,6 +95,10 @@
All changes to this project will be documented in this file.
+(ixwebsocket server) change legacy api with 2 nested callbacks, so that the first api takes a weak_ptr
(ixwebsocket) add WebSocketProxyServer, from ws. Still need to make the interface better.
This api was actually changed to take a weak_ptr
#include <ixwebsocket/IXWebSocketServer.h>
...
@@ -340,41 +341,49 @@ uint32_t m = webSocket.getMaxWaitBetweenReconnectionRetries();
ix::WebSocketServer server(port);
server.setOnConnectionCallback(
- [&server](std::shared_ptr<WebSocket> webSocket,
+ [&server](std::weak_ptr<WebSocket> webSocket,
std::shared_ptr<ConnectionState> connectionState,
std::unique_ptr<ConnectionInfo> connectionInfo)
{
std::cout << "Remote ip: " << connectionInfo->remoteIp << std::endl;
- webSocket->setOnMessageCallback(
- [webSocket, connectionState, &server](const ix::WebSocketMessagePtr msg)
- {
- if (msg->type == ix::WebSocketMessageType::Open)
+ auto ws = webSocket.lock();
+ if (ws)
+ {
+ ws->setOnMessageCallback(
+ [webSocket, connectionState, &server](const ix::WebSocketMessagePtr msg)
{
- std::cout << "New connection" << std::endl;
-
- // A connection state object is available, and has a default id
- // You can subclass ConnectionState and pass an alternate factory
- // to override it. It is useful if you want to store custom
- // attributes per connection (authenticated bool flag, attributes, etc...)
- std::cout << "id: " << connectionState->getId() << std::endl;
-
- // The uri the client did connect to.
- std::cout << "Uri: " << msg->openInfo.uri << std::endl;
-
- std::cout << "Headers:" << std::endl;
- for (auto it : msg->openInfo.headers)
+ if (msg->type == ix::WebSocketMessageType::Open)
{
- std::cout << it.first << ": " << it.second << std::endl;
+ std::cout << "New connection" << std::endl;
+
+ // A connection state object is available, and has a default id
+ // You can subclass ConnectionState and pass an alternate factory
+ // to override it. It is useful if you want to store custom
+ // attributes per connection (authenticated bool flag, attributes, etc...)
+ std::cout << "id: " << connectionState->getId() << std::endl;
+
+ // The uri the client did connect to.
+ std::cout << "Uri: " << msg->openInfo.uri << std::endl;
+
+ std::cout << "Headers:" << std::endl;
+ for (auto it : msg->openInfo.headers)
+ {
+ std::cout << it.first << ": " << it.second << std::endl;
+ }
+ }
+ else if (msg->type == ix::WebSocketMessageType::Message)
+ {
+ // For an echo server, we just send back to the client whatever was received by the server
+ // All connected clients are available in an std::set. See the broadcast cpp example.
+ // Second parameter tells whether we are sending the message in binary or text mode.
+ // Here we send it in the same mode as it was received.
+ auto ws = webSocket.lock();
+ if (ws)
+ {
+ ws->send(msg->str, msg->binary);
+ }
}
- }
- else if (msg->type == ix::WebSocketMessageType::Message)
- {
- // For an echo server, we just send back to the client whatever was received by the server
- // All connected clients are available in an std::set. See the broadcast cpp example.
- // Second parameter tells whether we are sending the message in binary or text mode.
- // Here we send it in the same mode as it was received.
- webSocket->send(msg->str, msg->binary);
}
}
);