【发布时间】:2016-02-18 03:35:09
【问题描述】:
我可以在这里使用实用程序客户端建立常规的 WS 连接,https://github.com/zaphoyd/websocketpp/blob/master/tutorials/utility_client/step6.cpp
但是我需要尝试安全的 WS 连接,并用下面的配置替换了配置并链接了所需的库。
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);
我收到:
连接创建尝试失败
【问题讨论】:
标签: sockets c++11 ssl websocket boost-asio