V
V
vadim64462021-07-22 07:28:19
C++ / C#
vadim6446, 2021-07-22 07:28:19

How to set up an encrypted connection?

I wrote a small program (unencrypted connection), I will post the code below. Tell me, please, where to dig to make an encrypted connection (wss)?

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

1 answer(s)
C
cunion, 2021-07-23
@0hquazEd

Read here .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question