Can UDP retransmit lost data?

13,145

Solution 1

It is common for clients to implement reliability on top of UDP if they need reliability (or sometimes just some reliability) but not any of the other things that TCP offers, for example strict in-order delivery, and if they want, at the same time, low latency (or multicast, where it works).

In general, you will only want to use reliable UDP if there are urgent reasons (very low latency and high speed needed, e.g. for a twitch game). In every "normal" case, simply using TCP will serve you equally well or better.
Also note that it is easy to implement your own stack on top of UDP that performs worse than TCP.

See enet for an example of a library that implements reliability (and some other features) on top of UDP (Raknet or HawkNL would be other examples).

Solution 2

Of course. You can build a reliable protocol (like TCP) on top of UDP.

Example

Imagine you are building a fileserver: * read the file using blocks of 1024 bytes * construct an UDP packet with payload: 4 bytes for the "position" in the file, 4 bytes for the "length" of the contents of the packet.

The receiver now receives UDP packets. If he gets following packets: * 0-1024: DATA * 1024-2048: DATA * 3072-4096: DATA

it realises a packet got missing, and asks the sending application to resend the part between 2048 and 3072.

This is a very basic example to explain your application code needs to deal with the packet construction and payload interpretation. Don't use it, it does not take edge cases (last packet, checksums for corrupted packets, ...) into account.

Solution 3

You might want to look at the answers to this question: What do you use when you need reliable UDP?

Share:
13,145
edwinNosh
Author by

edwinNosh

Updated on June 04, 2022

Comments

  • edwinNosh
    edwinNosh almost 2 years

    I know the protocol doesn't support this but is it common for clients that require some level of reliability to build into their application a method for requesting retransmission of a packet if found to be corrupt?