关闭后,Boost Beast重新连接websocket连接

时间:2018-06-27 17:57:53

标签: c++ c++11 boost boost-asio boost-beast

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

1 个答案:

答案 0 :(得分:0)

应该可以,尽管说实话我还没有测试过。重用时会发生什么?

相关问题