使用Websocket ++

时间:2018-05-18 14:37:16

标签: c++ ssl boost boost-asio websocket++

使用websocket ++作为websocket服务器的客户端我想使用客户端服务器的特定IP进行连接。所以我试图找出如何绑定到特定的IP,但它没有成功。

我认为on_socket_init处理程序可能用于配置套接字,但是这个处理程序:

void on_socket_init(websocketpp::connection_hdl hdl, boost::asio::ssl::stream<boost::asio::ip::tcp::socket> &s) {
    boost::asio::ip::tcp::endpoint localEndpoint(
            boost::asio::ip::address::from_string("192.168.178.28"), 0);

    std::cout << "Before bind is done " << s.lowest_layer().local_endpoint().address().to_string() << std::endl;
    s.lowest_layer().bind(localEndpoint);
    std::cout << "Bind is done " << s.lowest_layer().local_endpoint().address().to_string() << std::endl;

导致这种情况发生:

Before bind is done 192.168.178.28
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error> >'
  what():  bind: Invalid argument

在我的本地机器上,我没有多个IP,所以我只是想告诉它绑定到我拥有的一个IP,现在应该不会改变任何东西,除了验证我可以调用bind( )。然而它爆炸了,我不明白为什么。 在具有第二个IP的服务器上进行测试我得到了同样的错误。

使用gdb我只发现异常是由检查某些内部绑定调用的某些错误代码的函数抛出的。我不知道那个内部绑定调用的代码在哪里,除了&#34;无效的参数&#34;之外没有其他信息。或错误代码22.这只是无效参数的编号。

尝试分配我在我的机器上没有的伪造地址会产生不同的错误&#34; bind:无法分配请求的地址&#34;,所以猜测我传入的地址是好的。

这是否是正确的做法?

0 个答案:

没有答案