Ensuring packet order in UDP

前端 未结 4 1217
陌清茗
陌清茗 2021-01-04 20:21

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 v

相关标签:
4条回答
  • 2021-01-04 20:33

    there is no flow control (ICMP disabled)

    You can implement your own flow control using UDP:

    • Send one or more UDP packets
    • Wait for acknowledgement (sent as another UDP packets from receiver to sender)
    • Repeat as above

    See Sliding window protocol for further details.

    [This would be in addition to having a sequence number in the packets which you send.]

    0 讨论(0)
  • 2021-01-04 20:39
    is there a way to make sure winsock and send() will send the packets the same way they got there?

    It's called 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.

    0 讨论(0)
  • 2021-01-04 20:41

    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 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.

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

    0 讨论(0)
  • 2021-01-04 20:46

    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?

    0 讨论(0)
提交回复
热议问题