I am using boost beast WebSocket, and trying to bind it locally to a particular interface via bind, the bind happens(reflected in log), but in async connect handler I see some other endpoint (default interface), instead of the local one. Why can this be happening?
boost::optional<boost::beast::websocket::stream<boost::asio::ssl::stream<boost::asio::ip::tcp::socket>>> stream_;
boost::asio::socket_base::reuse_address option(true);
stream_->next_layer().next_layer().open(boost::asio::ip::tcp::v4());
stream_->next_layer().next_layer().set_option(option);
stream_->next_layer().next_layer().bind(boost::asio::ip::tcp::endpoint(
boost::asio::ip::address::from_string(interface_), 0));
auto local_endpoint = stream_->next_layer().next_layer().local_endpoint();
LOG("WS session:", session_id_, " from:", local_endpoint.address().to_string(),
local_endpoint.port(), interface_, stream_->next_layer().next_layer().native_handle());
here the logging is correct.
boost::asio::async_connect( stream_->next_layer().next_layer(), res.begin(), res.end(), boost::bind(&WebSocketSession::on_connect, this, boost::asio::placeholders::error) );
post this, in the handler (on_connect) the bind seems to be resetted to some other interface(default interface of the machine).
void on_connect(const boost::system::error_code& error) { auto tp = language::datetime::clock_realtime(); auto local_endpoint = stream_->next_layer().next_layer().local_endpoint(); LOG("WS session: on_connect from:", local_endpoint.address().to_string(), local_endpoint.port(),interface_,stream_->next_layer().next_layer().is_open(), stream_->next_layer().next_layer().native_handle());
In both cases is_open is logged as true and the native file descriptor is also same in both