Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何识别与websocketpp的连接_C++_Websocket - Fatal编程技术网

C++ 如何识别与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运行服务器的代码。我想确定到服务器的不同连接。为此,似乎应该使用
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:二进制'存在两个问题:

  • 您正在使用弱\u ptr作为密钥,而没有使用std::owner\u less。更多信息:
  • 在您的示例中,您使用套接字作为键,而不是连接hdl 解决方案:

    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) {}