【发布时间】:2011-12-07 14:27:20
【问题描述】:
我正在尝试将 boost asio tcp 套接字专门绑定到本地网络接口。什么时候调用socket上的bind()方法最合适?
_endpoint 指向远程 ip/port,例如192.168.0.15:8888.
// Invoke async. connect. Immediate return, no throw.
_socket.async_connect(_endpoint,
boost::bind(&MyTransceiver::handleConnect, this,
boost::asio::placeholders::error));
在MyTransceiver::handleConenct()内,我尝试了以下代码:
boost::asio::ip::tcp::endpoint local_end_point(
boost::asio::ip::address::from_string("192.168.0.55"), 6543 );
_socket.bind(local_end_point);
在这里调用它失败,在async_connect() 调用之前调用它,还有一个“无效句柄”异常。
【问题讨论】:
标签: networking boost interface bind boost-asio