The problem of UDP

It cover for 4 main issues:

  1. Data slicing - UDP datagrams cannot contain an infinite amount of information. Therefore, you will (often) need to slice your information into multiple datagrams and reconnect the puzzle pieces at the other end. For a given 'slicing', you need unique identifier and puzzle piece number.
  2. Never Reached - UDP datagrams can sometime get lost on the net. If a target peer does not receive an expected datagram, there should be a mechanism letting him request it again. Another method is to send a confirmation upon reception.
  3. Replay - Sometimes, you may receive the same UDP datagram twice (for complex reasons). The target peer should detect this.
  4. Out-of-order - The order of sending is not always the order of receiving. A target peer needs to handle this situation.

There is a protocol called slicing window which you could implement. I don't think you'll find a 3rd party library for this (though someone may prove me wrong here), because all the above is typically implemented by TCP itself.

原文地址:https://www.cnblogs.com/xiangshancuizhu/p/2713420.html