我可以在此处使用实用程序客户端建立常规的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);
我收到:
连接创建尝试失败
由于以下原因,我已经解决了该问题:https : //groups.google.com/forum/#!topic/websocketpp/SimAUzwZUVM
我必须制作on_tls_init
一个静态函数并像这样使用它(在获得连接之前):m_endpoint.set_tls_init_handler(connection_metadata::on_tls_init)
m_endpoint
客户对象在哪里。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句