WebSocketServer: Catch and ignore errors in Hello sending.

This commit is contained in:
tt2468 2021-04-29 09:14:03 -07:00
parent 561ba907d4
commit 724a63f1c8

View File

@ -279,12 +279,15 @@ void WebSocketServer::onOpen(websocketpp::connection_hdl hdl)
}
// Send object to client
websocketpp::lib::error_code errorCode;
auto sessionEncoding = session.Encoding();
if (sessionEncoding == WebSocketEncoding::Json) {
conn->send(helloMessage.dump());
std::string helloMessageJson = helloMessage.dump();
_server.send(hdl, helloMessageJson, websocketpp::frame::opcode::text, errorCode);
} else if (sessionEncoding == WebSocketEncoding::MsgPack) {
auto message = json::to_msgpack(helloMessage);
conn->send(message.data(), sizeof(message[0]) * message.size());
auto msgPackData = json::to_msgpack(helloMessage);
std::string messageMsgPack(msgPackData.begin(), msgPackData.end());
_server.send(hdl, messageMsgPack, websocketpp::frame::opcode::binary, errorCode);
}
}