I am making a game using a client-server model with UDP. Here's how I have implemented it so far:
- All packets include a sequence number and a flag specifying whether they are "important".
- Important message types require acknowledgement and will be re-sent after a delay if no acknowledgement is received.
- Most message types are "unimportant" - that is, they do not require an acknowledgement, and if such a message is received with an older sequence number than the latest, it is dropped.
My dilemma is this: if an "important" message arrives twice, I only want to process it once. But how will I know that I have already received it, without keeping an ever-expanding list in memory?
- Just remember the last X "important" messages received - the likelihood of receiving a VERY old message is slim (not ideal as it's not 100% reliable).
- Use TCP for "important" messages (not ideal due to the complications and overhead involved in managing 2 protocols simultaneously).
- Have a separate sequence number for "important" messages and ensure that these are always received in order, so only the most recent message needs to be remembered (I'm leaning towards this).
- Any other ideas?