beast icon indicating copy to clipboard operation
beast copied to clipboard

How to upgrade a SSL based ASIO socket to Beast WebSocket?

Open wonderbee77 opened this issue 3 years ago • 10 comments

Can you provide me an example code where the async SSL-based ASIO socket is moved to the beast socket to open up the websocket?

wonderbee77 avatar Mar 26 '22 04:03 wonderbee77

Sure, this is possible with latest asio as asio ssl streams became moveabke in boost 1.68

madmongo1 avatar Mar 26 '22 05:03 madmongo1

Any example code? I use boost 1.75. damn sure this is possible.

wonderbee77 avatar Mar 26 '22 15:03 wonderbee77

I can knock something up when I get home

madmongo1 avatar Mar 26 '22 15:03 madmongo1

Thank you so much:)

wonderbee77 avatar Mar 26 '22 15:03 wonderbee77

One thing I want to mention, I did the handshake using the Boost ASIO library and then moved the socket to Beast. After moving, I just have code to accept() and read() asynchronously.

wonderbee77 avatar Mar 26 '22 21:03 wonderbee77

seems like I am getting an uncaught exceptions when moving the socket:

`class webSocketConnection { public: using con_handle_t = std::list<std::shared_ptr<Connection>>::iterator; boost::beast::websocket::stream<boost::asio::ssl::streamboost::asio::ip::tcp::socket> web_socket;

        webSocketConnection(    con_handle_t con_handle, 
                                boost::asio::ssl::context& ssl_context ) :
                            web_socket(std::move(con_handle->get()->ssl_socket.next_layer()), ssl_context) { web_socket.accept(); }
};`

Creating object: capegen::webSocketConnection webSocketConnectionObj(con_handle, ssl_context);

wonderbee77 avatar Mar 26 '22 21:03 wonderbee77

seems like the boost ASIO handshake is not working if we open up a web socket connection from the browser...

wonderbee77 avatar Mar 26 '22 22:03 wonderbee77

OK. I am confused. I will just wait for your example program.

wonderbee77 avatar Mar 26 '22 22:03 wonderbee77

boost::beast::websocket::stream<boost::asio::ssl::streamboost::asio::ip::tcp::socket> web_socket;

Is the above code correct to define a web socket?

How do we move the SSL request and aync_accept on the Beast side?

Drilling down, I believe I face trouble in the moving request, accepting WebSocket connection.

wonderbee77 avatar Mar 26 '22 22:03 wonderbee77

Is this resolved?

vinniefalco avatar Jun 14 '22 17:06 vinniefalco