How to send websocket client request from a specific ip address

76 views
Skip to first unread message

S S

unread,
Mar 8, 2024, 1:47:55 PMMar 8
to WebSocket++
Hi Peter,
I am trying the following code for my websocket client to use a specific ip from my pc, but the request goes out to the server using another ip from my pc. My code:
bool WebSocketClient::WebSocketClientImpl::Connect( )
{
websocketpp::lib::error_code ec;
bool errorInit = false;

if ( isSecure )
{
if ( wssClient )
{
wssCon = wssClient->get_connection( uri, ec );
if ( !ec )
{
// Bind to specific IP address
asio::ip::tcp::endpoint endpoint(asio::ip::address::from_string("10.221.13.40"), 0);
wssClient->set_socket_init_handler([&endpoint](websocketpp::connection_hdl hdl, asio::ssl::stream<asio::ip::tcp::socket> & s) {
s.lowest_layer().open(endpoint.protocol());
s.lowest_layer().bind(endpoint);
});

wssClient->connect( wssCon );
mthread = make_unique<websocketpp::lib::thread>( &WebSocketClientImpl::WSSClient::run, wssClient );
}
}
else
errorInit = true;
}
}

Am I doing some thing wrong here ?

Please help.

Thanks,
SS





Reply all
Reply to author
Forward
0 new messages