c++ - 如何在 boost::beast 上保持 websocket?
问题描述
我在这里引用了有关 boost::beast websocket-async 的文档。
我在 on_read 函数上删除了 "ws_.async_close(websocket::close_code::normal..." 以避免断开连接。
但是野兽 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
推荐阅读
- graph-theory - 我们如何将 .gr 图形文件转换为 .cm 图形文件?
- vb.net - IIS Express - 未定义类型“DirectoryEntry”
- javascript - 按颜色和大小过滤产品数组
- c# - 已添加具有相同密钥的项目。键:调用 InfluxDB 的结果
- java - 计算一个巨大整数数组的任意两个数字之间的绝对最小差
- r - 带有 JSON 输入的 Digital Ocean 发布请求在管道工 API 中返回空白
- php - 如何根据 Laravel 8 中同一张表中的另一列在列中存储值
- r - 提供 RMarkdown 输出而不进行版本控制
- fastapi - Python Fastapi。重定向后没有标题
- arduino - 使用 IFTTT 和 Arduino 物联网云