I am working on a UDP system as well.
There are two categories of packets, some that need an acknowledge and some that don't need an acknowledge. Acknowledges and Re-order Messages are the ones that don't need an acknowledge (cause otherwise they would generate an endless loop) Let's call them packet type A (ack) and Type B (no ack) for now.
Every A packet has a serial number. This way the receiver will detect when a packet is missing: when it received packet 3 and then packet 5, it may send a re-order message of type B and ask for packet 4 that is missing.
For every successfully received packet the receiver will immeditalely send back an acknowledge packet of type B. So the server knows the receiver has got it.
Additionally the server may resend the packet if there was no acknowledge in a reasonable time, plus declare the receiver as logged out when it didn't respond for a certain time (eg. 2 Minutes).
Now to go a little further, missing packet are not the only problem, you also have to make sure the packets are not altered. For this purpose you may add a checksum to the header of every packet of type A. The receiver will only send the acknowledge if the integrity check has passed successfully.
For Anti-sabotage and Anti-cheating reasons you may kind of encrypt the checksum and keep the checksum method a secret, so people will fail to manually create cheat-packets.
So whenever a receiver is missing a packet in the serial sequence, or when it received a packet with a bad checksum, it may send a reorder request for the packet in question.
Hope this helps
|