C++ 如何识别与websocketpp的连接
我有一段使用websocketpp运行服务器的代码。我想确定到服务器的不同连接。为此,似乎应该使用C++ 如何识别与websocketpp的连接,c++,websocket,C++,Websocket,我有一段使用websocketpp运行服务器的代码。我想确定到服务器的不同连接。为此,似乎应该使用websocketpp::connection\u hdl hdl namespace websocketpp { /// A handle to uniquely identify a connection. /** * This type uniquely identifies a connection. It is implemented as a weak * pointer to t
websocketpp::connection\u hdl hdl
namespace websocketpp {
/// A handle to uniquely identify a connection.
/**
* This type uniquely identifies a connection. It is implemented as a weak
* pointer to the connection in question. This provides uniqueness across
* multiple endpoints and ensures that IDs never conflict or run out.
*
* It is safe to make copies of this handle, store those copies in containers,
* and use them from other threads.
*
* This handle can be upgraded to a full shared_ptr using
* `endpoint::get_con_from_hdl()` from within a handler fired by the connection
* that owns the handler.
*/
typedef lib::weak_ptr<void> connection_hdl;
编译器抱怨:
错误C2678:二进制'存在两个问题:
std::map<websocketpp::connection_hdl, boost::asio::ip::tcp::socket, std::owner_less<websocketpp::connection_hdl>> active_connections;
if (active_connections.count(con) > 0) {}
std::映射活动的\u连接;
if(active_connections.count(con)>0{}
但是,映射没有那么大意义:如果您有连接\u hdl,那么可以使用get\u socket()方法获取连接的套接字。我从未使用过这种方法,但我认为它应该有效吗?如果您只想存储所有打开的连接及其套接字,那么包含连接句柄的std::vector可能更好
std::map<websocketpp::connection_hdl, boost::asio::ip::tcp::socket, std::owner_less<websocketpp::connection_hdl>> active_connections;
if (active_connections.count(con) > 0) {}