Boost::asio WebSocket(tcp::no_delay 不起作用):- 2 条消息在客户端连接

问题描述 投票:0回答:0

我是 boost 库的新手。我正在编写一个 WebSocket 服务器。但面临一个问题,当我向客户端发送消息时,两条消息会串联在一起,首先发送“Hello”,然后发送“World”。但客户端收到“HelloWorld”。我将我的代码作为 zip 文件附加。为了解决这个问题,我在代码中做了这样的更改:-

beast::flat_buffer m_WriteBuffer;
    boost::beast::ostream(m_WriteBuffer) << message;
    ws_.async_write(m_WriteBuffer.data(),
                beast::bind_front_handler(
                    &WebSocketSession::on_write,
                    shared_from_this()));
        Sleep(100);

我在发送后添加了睡眠,然后它工作正常。 我还使用了 TCP NO_Delay 选项,但问题仍然存在。

声明:-

`boost::asio::io_context g_ioc{ 10 };

ssl::context g_ctx{ ssl::context::tlsv12 };

tcp::接受器 g_acceptor(net::make_strand(g_ioc));`

g_acceptor.set_option(tcp::no_delay(true), ec);
if (ec)
{
stl::log::trace(stl::log::LOG_GROUP_ERROR, stl::log::LOG_LEVEL_ERROR, "WebSocketListener::WebSocketListener set_option(No delay) failed, error message: %s", ec.message().c_str());
return;
}

您可以在以下链接找到我的代码:- 文字

请建议我如何解决这个问题

github boost boost-asio tcpserver boost-beast
© www.soinside.com 2019 - 2024. All rights reserved.