gpt4 book ai didi

c++ - 如何在 boost::beast 上保持 websocket?

转载 作者:行者123 更新时间:2023-11-30 05:00:42 24 4
gpt4 key购买 nike

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

为了避免断开连接,我删除了 on_read 函数上的“ws_.async_close(websocket::close_code::normal...”。

但是 beast websocket 通过结束 on_read 断开连接。

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

最佳答案

替换代码

    // 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

关于c++ - 如何在 boost::beast 上保持 websocket?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50617455/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com