如何在boost :: beast上继续使用websocket?

时间:2018-05-31 05:48:13

标签: c++ boost beast

我引用了关于boost :: beast websocket-async的here文档。

我删除了" ws_.async_close(websocket :: close_code :: normal ..." on onread函数,以避免断开连接。

但野兽websocket因结束on_read而断开连接。

std::make_shared<session>(ios)->run(host, port, text);
ios.run(); // I want to keep running it until explicit calling close.

1 个答案:

答案 0 :(得分:1)

替换代码

    // Close the WebSocket connection
    ws_.async_close(websocket::close_code::normal,
        std::bind(
            &session::on_close,
            shared_from_this(),
            std::placeholders::_1));

具有您想要的逻辑。你想做什么呢?你想读更多吗?然后像上面那样做另一个阅读:

    // Read a message into our buffer