确保 UDP 中的数据包顺序数据包、顺序、UDP

2023-09-07 12:44:35 作者:花落忆流年

我正在使用 2 台带有应用程序的计算机来发送和接收 udp 数据报.没有流量控制,ICMP 被禁用.通常,当我通过应用程序将文件作为 UDP 数据报发送时,我会收到两个数据包更改它们的顺序,因此 - 数据包丢失.

I'm using 2 computers with an application to send and receive udp datagrams. There is no flow control and ICMP is disabled. Frequently when I send a file as UDP datagrams via the application, I get two packets changing their order and therefore - packet loss.

我已经禁用了某种防火墙,并且计算机之间没有连接硬件开关(它们是直接连线的).

I've disabled and kind of firewall and there is no hardware switch connected between the computers (they are directly wired).

有没有办法确保 Winsock 和 send() 以它们到达那里的相同方式发送数据包?

Is there a way to make sure Winsock and send() will send the packets the same way they got there?

或者操作系统正在这样做?

Or is the OS doing that?

或者需要网络设备配置?

Or network device configuration needed?

推荐答案

UDP 是一种轻量级协议,设计上不处理数据包排序之类的事情.如果您想要稳健的数据包传输和排序,TCP 是更好的选择.

UDP is a lightweight protocol that by design doesn't handle things like packet sequencing. TCP is a better choice if you want robust packet delivery and sequencing.

UDP 通常设计用于数据包丢失可接受或优于 TCP 必须重新请求数据包时产生的延迟的应用程序.因此,UDP 通常用于媒体流.

UDP is generally designed for applications where packet loss is acceptable or preferable to the delay which TCP incurs when it has to re-request packets. UDP is therefore commonly used for media streaming.

如果您仅限于使用 UDP,则必须开发一种方法来识别乱序数据包并对其重新排序.

If you're limited to using UDP you would have to develop a method of identifying the out of sequence packets and resequencing them.