Is it possible to guarantee delivery of messages using UDP on Node.js? -


how possible guarantee delivery of messages using udp on node.js? example, resend packet if failed - there way identify when failed? also, how common loss of packet?

if you're wondering "how detect lost packets"? general technique have receiver send acknowledgement each packet sent. if transmitter not receive acknowledgement must resend packet. if receiver gets duplicate packets should discard duplicate.

the basic scheme this:

tx                               rx  \           data   `----------------------------->                ack               /  <-----------------------------'   \           data   `-------------------- - - -          loss of data packet                .                .                . timeout                .  \       data retransmit   `----------------------------->                ack               /  <-----------------------------'   \           data   `----------------------------->                ack               /       - - - - -----------------'       loss of ack packet                .                . timeout                .   \       data retransmit   `----------------------------->                ack               /  <-----------------------------' 

this basis of forms of packet loss detection. there several refinements can implemented improve technique basics same: if receiver not tell packet has arrived packet lost.

one of first improvement done algorithm check ack appropriate ack , not echo sent router or signal cross inteference or software bug. solution implement toggle bit. data packet transmitted toggle bit set value , ack packet needs reply appropriate value (usually same value). if toggle bit wrong means ack packet doesn't match last data packet implies matches previous data packet. implies last data packet hasn't been acknowledged means has gone wrong , packet should retransmitted until correct ack received.

tx                               rx  \           data[0]   `----------------------------->                ack[0]            /  <-----------------------------'   \           data[1]   `----------------------------->                ack[0]            /  <-----------------------------'      ack mismatch!   \       data[1] retransmit   `-----------------------------> 

several real world protocols use technique including protocols used control industrial equipment , robots.

the next step expansion of above idea. instead of sending bit why not send number. way can more match ack data packet , more accurately detect packet lost , needs retransmission. technique referred sliding window technique because @ point number rolls on , slides zero. , maximum number of packets can transmit before you're unable detect packet loss sliding window size.

the big advantage of sliding window technique can send lots of data packets without waiting ack. improves throughput:

 \           data[1]   `----------------------------->  \           data[2]   `----------------------------->  \           data[3]   `----------------------------->                 ack[1]            /  <-----------------------------'               ack[2]            /  <-----------------------------'   \           data[4]   `----------------------------->  \           data[5]   `----------------------------->                ack[3]            /  <-----------------------------'               ack[5]            /  <-----------------------------'      ack[4] missing!                .                . timeout                .   \       data[4] retransmit   `-----------------------------> 

so above short summary of basic technique detecting packet loss. that's need implement if want udp packets arrive @ destination.

you should know though tcp implements should use tcp if don't want reinvent wheel. udp created because in cases packet loss ok (think audio/video streaming).


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -