Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If what you're really wondering is "how do I detect lost packets"? Then the general technique is to have the receiver send an acknowledgement for each packet sent. If the transmitter does not receive an acknowledgement then it must resend the packet. If the receiver gets duplicate packets then it should discard the duplicate.</p> <p>The basic scheme is this:</p> <pre><code>TX RX \ data `-----------------------------&gt; ack / &lt;-----------------------------' \ data `-------------------- - - - loss of data packet . . . timeout . \ data retransmit `-----------------------------&gt; ack / &lt;-----------------------------' \ data `-----------------------------&gt; ack / - - - - -----------------' loss of ack packet . . timeout . \ data retransmit `-----------------------------&gt; ack / &lt;-----------------------------' </code></pre> <p>This is essentially the basis of all forms of packet loss detection. There are several refinements that can be implemented to improve the technique but the basics is generally the same: if the receiver does not tell you that the packet has arrived then the packet is lost.</p> <p>One of the first improvement generally done to the algorithm is to check that the ack is really the appropriate ack and not just some echo sent by the router or by signal cross inteference or by a software bug. The solution is to implement a toggle bit. The data packet is transmitted with the toggle bit set to a value and the ack packet needs to reply with the appropriate value (usually the same value). If the toggle bit is wrong then it means that the ack packet doesn't match the last data packet which implies that it matches the previous data packet. This implies that the last data packet hasn't been acknowledged which means that something has seriously gone wrong and the packet should be retransmitted until the correct ack is received.</p> <pre><code>TX RX \ data[0] `-----------------------------&gt; ack[0] / &lt;-----------------------------' \ data[1] `-----------------------------&gt; ack[0] / &lt;-----------------------------' ack mismatch! \ data[1] retransmit `-----------------------------&gt; </code></pre> <p>Several real world protocols use this technique including most protocols used to control industrial equipment and robots.</p> <p>The next step is actually an expansion of the above idea. Instead of sending just a bit why not send a number. That way you can more definitely match the ack to the data packet and so more accurately detect which packet was lost and needs retransmission. This technique is often referred to as the sliding window technique because at some point the number rolls over and slides back to zero. And so the maximum number of packets you can transmit before you're unable to detect packet loss is the sliding window size.</p> <p>The big advantage of the sliding window technique is that you can send lots of data packets without waiting for the ack. This significantly improves throughput:</p> <pre><code> \ data[1] `-----------------------------&gt; \ data[2] `-----------------------------&gt; \ data[3] `-----------------------------&gt; ack[1] / &lt;-----------------------------' ack[2] / &lt;-----------------------------' \ data[4] `-----------------------------&gt; \ data[5] `-----------------------------&gt; ack[3] / &lt;-----------------------------' ack[5] / &lt;-----------------------------' ack[4] missing! . . timeout . \ data[4] retransmit `-----------------------------&gt; </code></pre> <p>So the above is a short summary of the basic technique for detecting packet loss. That's what you need to implement if you want all your UDP packets to arrive at their destination.</p> <p>You should know though that TCP already implements this so you should really use TCP if you don't want to reinvent the wheel. UDP was created because in some cases packet loss is OK (think audio/video streaming).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload