My websocket server URL is ws://localhost/webstream/wsocket Iam trying to create a C++ websocket client that connects to this server using boost
tcp::resolver resolver{ioc};
_pws = new websocket::stream<tcp::socket>(ioc);
// Look up the domain name
// my server is http://localhost/webstream/wsocket
_host = "localhost";
_port = 80;
auto const results = resolver.resolve(_host, std::to_string(_port));
if(results.size() == 0)
{
std::cout<<"failed to connect to websocket server"<<std::endl;
delete _pws;
_pws = nullptr;
return;
}
// Make the connection on the IP address we get from a lookup
net::connect(_pws->next_layer(), results.begin(), results.end());
// Set a decorator to change the User-Agent of the handshake
_pws->set_option(websocket::stream_base::decorator(
[](websocket::request_type& req)
{
req.set(http::field::user_agent,
std::string(BOOST_BEAST_VERSION_STRING) +
" websocket-client-coro");
}));
_pws->handshake(host, "/");
But iam unable to connect to sever. How can i set the path "/webstream/wsocket" to connect. '''
What I have tried:
i tried with
_host = "localhost/webstream/wsocket";
_port = 80;
_pws->handshake(host, "/webstream/wsocket");
but not getting connected In boost library, how can we specify the path of websocket server