I wish you luck in this
probably going to need that.
At first when thinking about it it dosent seem to difficult.
all outgoing 'guaranteed messages' get an incrementing id
all outgoing guaranteed messages are placed in a hashtable with their id's as indexes.
if a message with something like 'ACK <id#>' arrives remove the entry for that id.
That dosent seem to hard, could probably whip that up in a few minutes. The problem comes with the resending of unaknowledged packets.
You could brute force it like the quake3 boys did, resend all unackowledged packets every 100ms (or less) untill they are acknowledged or the client drops. This does seem like the easiest and best way to make sure packets get there in time critical applications. But how would that look over the net, especially if there are a few hundred clients. I'm pretty sure my server wouldent be to happy with me. Any better ideas are greatly appreciated.
And dealing with the case of lost ack's dosent get to complicated this way either.
lets say im sending messages with the following syntax '<ackFlag> <type> <id> <message>'.
ackFlag is 0 or 1, if it is 0 the client or server whoever received it dont care about acknowlading the packet, they just deal with it.
if the flag is 1 they send a response message with the id of the packet. Even if they did receive it before they send the ack ( takes out lost ack problem ) but then they later discard it when they notice that the id of the packet is old.
Thinking about this i also realised another problem. What if an older guranteed message arrives after a new one, its ID would be older than the new one that arrived before it and hence it would be difficuclt to tell with just an incrementing ID if it had already been dealt with. Best way (a way atleast) to remove this could be too keep the last 20 seconds worth of received ID's in a table and test all incomming messages against it, if it isent in table it hasent been received, if it is, drop it like its radioactive.
I'm at the moment not sure how else to go about guranteeing UDP messages.
To restate what others have said before for non guranteed UDP, all you have to do is send the messages with incrementing ID, if an ID of a packet is lower than a previously accepted packet its old, discard it.
My biggest problem, or what i think is the MOST unpretty about this is the way i would test if ive already received a guranteed packet. theres gotta be a better way to do that.