gpt4 book ai didi

c++ - TCP 数据包有时会合并(并且延迟?)

转载 作者:行者123 更新时间:2023-11-30 18:11:19 26 4
gpt4 key购买 nike

我每 500 毫秒从服务器向客户端发送数据包,反之亦然,以表明连接仍然有效。然而,有时这些数据包会被延迟并且多个数据包被组合在一起。问题是,这可能会导致“连接超时”,而这可能只是延迟。

在任何现代互联网连接上,数据包发送 10 秒的延迟对我来说似乎相当长。关于如何解决这个问题有什么想法吗?

在服务器和客户端上,消息的发送和接收如下例所示,其中最终接收到的数据包由多个数据包组合而成。这同时发生在服务器和客户端上。

SENT ALIVE PACKET
RECEIVED ALIVE PACKET
SENT ALIVE PACKET
RECEIVED ALIVE PACKET
SENT ALIVE PACKET
RECEIVED ALIVE PACKET
SENT ALIVE PACKET
RECEIVED ALIVE PACKET
SENT ALIVE PACKET
RECEIVED ALIVE PACKET
SENT ALIVE PACKET
SENT ALIVE PACKET
SENT ALIVE PACKET
RECEIVED ALIVE PACKET
RECEIVED ALIVE PACKET
SENT ALIVE PACKET
RECEIVED ALIVE PACKET
SENT ALIVE PACKET
RECEIVED ALIVE PACKET
SENT ALIVE PACKET
RECEIVED ALIVE PACKET
SENT ALIVE PACKET
SENT ALIVE PACKET
SENT ALIVE PACKET
SENT ALIVE PACKET
SENT ALIVE PACKET
SENT ALIVE PACKET
SENT ALIVE PACKET
SENT ALIVE PACKET
RECEIVED ALIVE PACKET RECEIVED ALIVE PACKET RECEIVED ALIVE
PACKET RECEIVED ALIVE PACKET RECEIVED ALIVE PACKET RECEIVED ALIVE
PACKET RECEIVED ALIVE PACKET RECEIVED ALIVE PACKET RECEIVED ALIVE
PACKET RECEIVED ALIVE PACKET ****RECEIVED TIMEOUT PACKET****

Connection Timeout.


编辑

在我运行相同代码的另一台电脑上从未发生过这种情况。

编辑2

数据包的合并没有问题,但数据包应该直接发送,不要延迟。

最佳答案

KEEPALIVE 选项添加到我的套接字似乎已经解决了这个问题。

感谢@cdarke。

关于c++ - TCP 数据包有时会合并(并且延迟?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48526637/

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