windows 确保 UDP 中的数据包顺序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3745115/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ensuring packet order in UDP
提问by Davidallencoe
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.
我正在使用 2 台带有应用程序的计算机来发送和接收 udp 数据报。没有流量控制,ICMP 被禁用。通常当我通过应用程序将文件作为 UDP 数据报发送时,我会收到两个数据包改变它们的顺序,因此 - 数据包丢失。
I've disabled and kind of firewall and there is no hardware switch connected between the computers (they are directly wired).
我已经禁用了某种防火墙,并且计算机之间没有连接硬件开关(它们是直接连接的)。
Is there a way to make sure Winsock and send()
will send the packets the same way they got there?
有没有办法确保 Winsock 并按照到达那里的方式send()
发送数据包?
Or is the OS doing that?
或者操作系统正在这样做?
Or network device configuration needed?
或者需要网络设备配置?
回答by PaulG
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 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 通常设计用于数据包丢失可接受或优于 TCP 必须重新请求数据包时产生的延迟的应用程序。因此,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.
如果您仅限于使用 UDP,则必须开发一种方法来识别乱序数据包并对其重新排序。
回答by crazyscot
UDP does not guarantee that your packets will arrive in order. (It does not even guarantee that your packets will arrive at all.) If you need that level of robustness you are better off with TCP. Alternatively you could add sequence markers to your datagrams and rearrange them at the other end, but why reinvent the wheel?
UDP 不保证您的数据包会按顺序到达。(它甚至不能保证您的数据包会到达。)如果您需要这种级别的健壮性,您最好使用 TCP。或者,您可以向数据报添加序列标记并在另一端重新排列它们,但为什么要重新发明轮子呢?
回答by Steve-o
is there a way to make sure winsock and send() will send the packets the same way they got there?
有没有办法确保 winsock 和 send() 会以与到达那里相同的方式发送数据包?
It's called TCP.
它被称为 TCP。
Alternatively try a reliable UDP protocol such as UDT. I'm guessing you might be on a small embedded platform so you want a more compact protocol like Bell Lab's RUDP.
或者尝试可靠的 UDP 协议,例如UDT。我猜你可能在一个小的嵌入式平台上,所以你想要一个更紧凑的协议,比如贝尔实验室的RUDP。
回答by ChrisW
there is no flow control (ICMP disabled)
没有流量控制(禁用 ICMP)
You can implement your own flow control using UDP:
您可以使用 UDP 实现自己的流量控制:
- Send one or more UDP packets
- Wait for acknowledgement (sent as another UDP packets from receiver to sender)
- Repeat as above
- 发送一个或多个UDP数据包
- 等待确认(作为另一个 UDP 数据包从接收方发送到发送方)
- 重复如上
See Sliding window protocolfor further details.
有关更多详细信息,请参阅滑动窗口协议。
[This would be in addition tohaving a sequence number in the packets which you send.]
[这将是您发送的数据包中的序列号的补充。]