I am currently working on a network abstraction layer that will be able to deliver reliable and unreliable messages over UDP.
Each UDP packet contains a user id, the current sequence number, an ACK field and an ACK bitfield (as described here) and a payload among other things like the current tick.
The payload contains the games messages. Each message is simply a message type id followed by the message data.
I now want to be able to send certain message reliably and unreliably, but that seems to be very tricky if I have packets that contain mixed message types, due to the fact that the ACK field refers to the packet and not to its content. Three solutions came to my mind:
- Send all packets reliably (most simple solution, but I am not sure how big the effect on network performance would be)
- Don't mix message of different reliablity type in the packets payload. Have packets that only contain reliable messages and packets that only contain unreliable messages, but let unreliable packets be able to acknowledge reliable packets. The question here would be, how frequently should reliable and unreliable messages be sent? Sometimes there might even be no reliable messages to be send, because they're only created for consistent events (in my specific use case). If I'd send let's say 20 packets per second, what percentage of those should be reliable packets that contain only reliable messages?
- Have a sequence number and a reliability flag for each payload and treat them like single packets, but bundle them together before sending them over the network.
What would be the best approach to do that? Is there maybe a fourth alternative that I didn't think of that could solve all my problems?
Thanks in advance.
Greetings,
Pfaeff