2015-11-16 105 views
2

我可以在这里使用实用程序客户端建立常规WS连接,但我需要尝试一个安全的WS连接,并用下面的配置替换配置并链接所需的库。如何建立与C++库websocket ++的安全套接字连接?

typedef websocketpp::client<websocketpp::config::asio_tls_client> client;

我的处理程序是这样的:

typedef std::shared_ptr<boost::asio::ssl::context> context_ptr; 

// part of class connection_metadata 
static context_ptr on_tls_init(websocketpp::connection_hdl) { 
    context_ptr ctx = std::make_shared<boost::asio::ssl::context>(boost::asio::ssl::context::sslv23); 

    try { 
     ctx->set_options(boost::asio::ssl::context::default_workarounds | 
         boost::asio::ssl::context::no_sslv2 | 
         boost::asio::ssl::context::no_sslv3 | 
         boost::asio::ssl::context::single_dh_use); 
    } catch (std::exception& e) { 
     std::cout <<"Error in context pointer: "<< e.what() << std::endl; 
    } 
    return ctx; 
} 

// part of class websocket_endpoint 
con->set_tls_init_handler(bind(&connection_metadata::on_tls_init,metadata_ptr,std::placeholders::_1)); 

当我尝试以下行来获取连接:

client::connection_ptr con = m_endpoint.get_connection(uri, ec); 

我收到:

连接创建尝试失败

回答