gpt4 book ai didi

c++ - 发送较少字节数的 TCP 套接字

转载 作者:太空宇宙 更新时间:2023-11-04 11:09:40 27 4
gpt4 key购买 nike

我正在尝试使用 boost.asio 库发送大量字节,如下所示:

void tcp_send(boost::asio::io_service &io, const char *dst_ip, uint16 dst_port)
{
uint8 *sbuff;
size_t slen;
ip::tcp::socket sock(io);

sock.connect(ip::tcp::endpoint(ip::address::from_string(dst_ip), dst_port));

sbuff = new uint8[100412];
sbuff[0] = 67;
sbuff[1] = 193;
sbuff[2] = 136;
sbuff[3] = 60;

boost::asio::async_write(sock, boost::asio::buffer(sbuff, 100412),
boost::bind((&send_handler), placeholders::error));
}

当我使用 wireshark 检查传输的字节数时,发件人始终只发送 65536 字节的数据,不包括 TCP header 字节。那么可能是什么问题呢?有没有我需要修改的参数。

我在 linux ubuntu 上运行应用程序。好像最大传输字节数是2^16。

Wireshark TCP Stream Flow

最佳答案

TCP 是一个。 IP 数据报或以太网帧中出现多少字节应该与您无关。

成功调用send 并不一定意味着数据已经发送;只是 TCP 堆栈接受了数据并 promise 发送它(除非您指定 PSH)。

关于c++ - 发送较少字节数的 TCP 套接字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23795586/

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