我正在使用 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)));
}