4

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

1 回答 1

1

这应该有效,但老实说我还没有测试过。当你重复使用它时会发生什么?

于 2018-06-30T12:00:39.800 回答