Click here to Skip to main content
15,882,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My websocket server URL is localhost/webstream/wsocket
Iam trying to create a C++ websocket client that connects to this server using boost.

<pre>tcp::resolver resolver{ioc};
        _pws = new websocket::stream<tcp::socket>(ioc);
        //websocket::stream<tcp::socket> ws{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
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900