首页 > 解决方案 > 在短缺时间缓冲 UDP 数据包

问题描述

我的情况是Linux客户端正在使用UDP Socket。客户端正在发送消息,如果 10 秒内没有响应,客户端将每隔 10 秒重试一次。

情况是当连接断开时,客户端发送了许多试验,同时服务器端没有收到任何内容。连接建立后,我发现服务器上同时收到所有先前的消息,这意味着它已被缓冲,并且由于服务器端同一时刻收到的重复消息而导致很多问题。

客户端上的 TCPDUMP:

21:01:14.691903 IP 172.123.13211 > 172.34.13211: length 88  "1st at second 14"  
21:01:24.692791 IP 172.123.13211 > 172.34.13211: length 88  "2nd at second 24"  
21:01:34.694930 IP 172.123.13211 > 172.34.13211: length 88  "3rd at second 34"  
21:01:44.696020 IP 172.123.13211 > 172.34.13211: length 88  "4th  ate second 44"   

连接建立后服务器 TCPDUMP:

12:02:01.509518 IP 172.123.13211 > 13211: length 88 "Received 1st at second 1"       
12:02:01.517841 IP 172.123.13211 > 13211: length 88 "Received 2nd at second 1"    
12:02:01.543759 IP 172.123.13211 > 13211  length 88 "Received 3rd at second 1"    
12:02:01.550741 IP 13211 > 172.123.13211: length 36   
12:02:01.567948 IP 172.123.13211 > .13211: length 88

我需要了解使用 UDP 套接字并且 Connection is down 的情况。如何避免在短缺期间缓冲数据包

客户端代码是 C++ 谢谢

标签: linuxsocketsnetworkingudp

解决方案


你可能正在寻找这个:

如何在 C 中刷新 UDP 套接字的输入缓冲区?

您在问题中使用的语言也是错误的。请更加干净和准确,并使用相关术语


推荐阅读