c++ - 关闭后Boost Beast重新连接websocket连接
问题描述
我正在使用 boost::beast 创建一个 websocket 连接,到目前为止它似乎工作正常。但是我无法确定是否应该在断开连接后替换 websocket::stream 变量。
即我有一个变量:
boost::beast::websocket::stream<boost::asio::ssl::stream<boost::asio::ip::tcp::socket>> _ws
启动并完成异步断开连接后:
bool WebsocketConnection::startDisconnectSequence()
{
_ws.async_close(
boost::beast::websocket::close_code::normal,
boost::asio::bind_executor(
_strand,
std::bind(
&WebsocketConnection::onClose,
this,
std::placeholders::_1)));
return true;
}
如果我想重新启动,我应该更换 _ws 变量
boost::asio::async_connect(
_ws.next_layer().next_layer(),
results.begin(),
results.end(),
boost::asio::bind_executor(
_strand,
std::bind(
&ASIOConnectionBase::onConnect,
this,
std::placeholders::_1)));
}
解决方案
这应该有效,但老实说我还没有测试过。当你重复使用它时会发生什么?
推荐阅读
- sql - 无法使用 AWS S3 Select 对 JSON 进行查询
- angular - 使用 Angular 7 通过按钮增加字体大小
- c# - services.AddSingleton
.NET Core 中的用途 - azure - Azure Devops Rest API - 找出特定代理池上的队列作业
- java - Vert.x:在不丢弃新消息的情况下处理 Rabbitmq 消费者背压
- java - “android”命令已弃用。苹果系统
- android - 单个 Cordova 项目中的多个 Cordova 应用程序
- javascript - 如何从字母表中选择字母显示该字母的文本?香草 Javascript
- cassandra - 启动 Cassandra 3.11.2 时遇到错误
- sql - 点燃数据库时间戳列默认为当前时间戳失败