Feedback on reliable UDP implementation

So, I’ve implemented a reliable UDP implementation. I am wondering if it can be improved. I don’t care in which order the packets arrive. Here is the idea:

When the server sends a packet it sets the sequence number that is located in the end. If the packet is reliable it is stored at the index of the sequence number in an array.

If the client received a packet it first checks the sequence number. If it equals 0 then it’s an unreliable packet - just handle it and continue. Otherwise, if it’s not a NAK or a ping, the sequence number is compared against the last received packet’s. If it is newer/more recent then mark every sequence number between the last and the just received as missing. Update the last received number and mark the packet as received.
Then, til a packet has been received, send NAK:s to the server with the sequence number of the missing packet.

If the server receives a NAK-packet then it just resends the packet as in the array of sent packets. If all packets sent to the client get lost, then there would be no chance of telling if a packet was sent. Pings solve this problem by consisting of the sequence number of the last sent packet.

Keep sending everything that isn’t ACKed.

the idea is good. it’s pretty much what TCP does for you out of the box. that’s the bad news tho’.

as Riven says, it’s probably faster just resending everything - or using TCP, not having the overhead in the code and allowing the NIC driver dealing with the sequence.

It’s not neccessary to treat all the packets as reliable. A part of them may be remaining unreliable as in the ordinary UDP.

I simply mark important packets as ACKREQUIRED, and just resend the packet over and over till it’s ACKed. It’s a really simple solution and works wonders.

I don’t check which packet is newer or anything, just because packets I mark as ACKREQUIRED will be received for sure. I feel like checking what packet is newer and comparing it and resending all packets that where from x packet to x packet is over doing it in your situation.