【问题标题】:Boost websocket accept hangsBoost websocket接受挂起
【发布时间】:2018-04-10 14:17:32
【问题描述】:

我从herehere 复制了简单的boost websocket 示例,效果很好。然后,我在调用创建 websocket 之前将这些行添加到服务器:

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

这些行取自this page,用于在升级到 websocket 之前读取消息的内容。服务器和客户端现在都挂在 websocket 握手上。

是我做错了什么还是这是 boost 中的错误?

【问题讨论】:

    标签: c++ boost websocket


    【解决方案1】:

    如果您要自己阅读 WebSocket 升级请求,那么为了接受升级请求,您需要使用正确的重载 websocket::stream::acceptwebsocket::stream::async_accept。在第一个参数中使用接受 HTTP 请求的重载: 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

    【讨论】:

    • 谢谢!就是这样!
    猜你喜欢
    • 2019-02-27
    • 2012-09-14
    • 1970-01-01
    • 2021-12-22
    • 2016-01-23
    • 1970-01-01
    • 1970-01-01
    • 2017-06-15
    • 2012-10-13
    相关资源
    最近更新 更多