gpt4 book ai didi

sockets - 如何使用升压冲洗 socket

转载 作者:行者123 更新时间:2023-12-03 12:01:38 27 4
gpt4 key购买 nike

我正在实现使用boost将xml发送到客户端的服务器。我面临的问题是缓冲区不会立即发送并累积到一个点,然后发送整个内容。这在我的客户端造成了一个问题,当它解析xml时,它可能具有不完整的xml标记(不完整的消息)。有什么方法可以在需要发送消息时刷新套接字吗?下面是服务器的写代码。

void 
ClientConnection::handle_write(const boost::system::error_code& error)
{

if (!error)
{

m_push_message_queue.pop_front ();
if (!m_push_message_queue.empty () && !m_disconnected)
{

boost::asio::async_write(m_socket,
boost::asio::buffer(m_push_message_queue.front().data(),
m_push_message_queue.front().length()),
boost::bind(&ClientConnection::handle_write, this,
boost::asio::placeholders::error));
}
}
else
{
std::err << "Error writting out message...\n";
m_disconnected = true;
m_server->DisconnectedClient (this);

}
}

最佳答案

通常,在使用TCP字节流创建应用程序时,发送方发送固定长度的 header ,以便接收方知道需要多少字节。然后,接收器读取那么多字节,并将结果缓冲区解析为XML对象。

关于sockets - 如何使用升压冲洗 socket ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3345309/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com