V
V
vadim64462021-07-21 08:33:32
ASIO
vadim6446, 2021-07-21 08:33:32

How to make a web socket available outside the same network?

Good afternoon!
I started to study the boost library, asio. Everything works on the local network, now I'm trying to make the socket accessible from outside, there is a server, a static ip address. On the router, I made port forwarding static_ip: 8083-> 192.168.0.52: 8083, but the socket is not available. Tell me, please, where to dig to make the socket available?

Here is the code:

auto const address = boost::asio::ip::make_address("192.168.0.52");
auto const port = static_cast<unsigned short>(std::atoi("8083"));

boost::asio::io_context ioc{1};

tcp::acceptor acceptor{ioc, {address, port}};

while(1){
    tcp::socket socket{ioc};
    acceptor.accept(socket);
    std::cout<<"socket accepted"<<std::endl;

    std::thread{[q = std::move(socket)]() mutable {
        boost::beast::websocket::stream<tcp::socket> ws {std::move(q)};
        ws.write_buffer_bytes(32789);
        ws.accept();
        ws.binary(true);

        while(1){
            try{
            	boost::beast::flat_buffer buffer;
                ws.read(buffer);
                ws.write(boost::asio::buffer(std::string("Hello World")));
            }
            catch(boost::beast::system_error const& se){
                if(se.code() != boost::beast::websocket::error::closed){
                    std::cout << se.code().message() << std::endl;
                    break;
                }
            }
        }
  }}.detach();
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Drno, 2021-07-21
@Drno

Does the firewall allow connections from outside?

V
vadim6446, 2021-07-21
@vadim6446

The cause of the error was incorrect configs on the router

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question