Choose a delivery policy for missing, duplicate, and late datagrams.
Lesson goal
Trace two game-state updates and decide which datagrams the application should use, ignore, or recover.
Before you begin — TCP.
UDP (User Datagram Protocol) sends individual messages called datagrams. A game can send each position snapshot as soon as it is ready. If tick 1 is lost, a receiver that gets the complete snapshot for tick 2 can apply it immediately. The tick numbers and the decision to advance belong to the game.
Each datagram carries its own payload and port information. UDP preserves message boundaries and lets a sender transmit without a transport handshake. A datagram can be lost, duplicated, or delivered after a later datagram. If the application needs acknowledgements, retransmissions, or ordering, it must supply that behavior or choose a protocol that does.
The game can attach an increasing tick number to every complete position snapshot. Suppose snapshots 1 and 3 arrive, then snapshot 2 arrives late. After applying 3, the receiver discards 2. Applying it would move the player back to an older position. This works because snapshot 3 contains everything needed to place the player. An update expressed only as a change from snapshot 2 would have a different recovery requirement.
Suppose an audio frame is missing at its playback deadline. The application can conceal the gap and play the next frame. A playback buffer gives late frames more time to arrive, at the cost of additional delay before the listener hears the audio.
An application using UDP can request a retransmission while it would still be useful. It also needs to respond to network congestion. The actual delay depends on conditions along the path and on the application’s recovery policy. UDP usage guidelines
A game sends a position snapshot and a purchase request. Could it discard either message as soon as a newer message arrives?
A newer complete snapshot can supersede an older position. A purchase represents a lasting action. It needs a way to confirm the outcome and to handle a retry without charging the player twice.