简体   繁体   中英

Boost websocket accept hangs

I copied the simple boost websocket example from here and here , and that worked fine. I then added these lines to the server just before the call to create the websocket:

boost::beast::flat_buffer buffer;
boost::beast::http::request<boost::beast::http::string_body> req;
boost::beast::http::read(sock, buffer, req);

Thse lines are taken from this page to read the contents of the message before upgrading to a websocket. Both the server and client now hang on the websocket handshake.

Am I doing something wrong or is this a bug in boost?

If you are going to read the WebSocket upgrade request yourself, then in order to accept the upgrade request you need to use the correct overload of websocket::stream::accept or websocket::stream::async_accept . Use an overload which accepts the HTTP request in the first parameter: https://www.boost.org/doc/libs/1_66_0/libs/beast/doc/html/beast/ref/boost__beast__websocket__stream/accept/overload6.html https://www.boost.org/doc/libs/1_66_0/libs/beast/doc/html/beast/ref/boost__beast__websocket__stream/async_accept/overload3.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM