Introduction
So I’ve recently just quit Minecraft due to everyone trying to make money out of it and ruining the game for me. In fact, it’s been so recent that I haven’t had a chance to get a decent username and change my avatar… I don’t know whether people write introduction posts on here, so I am going to include mine in this post. Hi.
The Problem
The game, which I am working on currently has ~20 types of packets, ~6 of which are critical.
I don’t really want to use TCP for only a quarter of packets sent, especially since critical packets aren’t sent very frequently in the game and wasting resources isn’t a great idea.
Here are some solutions that I have thought of. If you could let me know what you think, that would be great. Thank you.
The Chosen Solution
As suggested by princec, the best solution seems to be to store an array of unconfirmed critical packets for each Client and resend them every game tick, until the Client sends a valid confirmation packet for each critical packet that is being resent. Thank you
[s]Solution One
The loss rate is 1% to 5% depending on network latency, so assuming it’s 5%, that’s 1/20 packets lost.
However, if critical packets are resent once, that 0.05 chance becomes 0.0025, and if they are resent twice, the chance decreases to 0.000125, so only 1 in 8000 critical packets are lost. I don’t actually like this solution, since 1 in 8000 games could be messed up for someone, somewhere.
Solution Two
When a critical packet is received by the client, they send a confirmation packet to the server. This contains the critical packet’s identification byte (first byte that defines what the packet does) and the length or checksum of the packet. If the receiver does not get this confirmation packet within , the critical packet is resent. This cycle is repeated until a valid confirmation packet arrives.
Solution Three
Use client prediction. Basically, the client decides when it should be receiving critical packets. E.g. when an LivingEntityMovement packet is received for a LivingEntity that doesn’t exist (for the client), they request that LivingEntity’s join packet to be resent. This should be hardly noticeable by the player.
Solution Four
Switch to TCP. I do not like this option at all because I’d have to rewrite my rather simple UDP library to make it into a TCP library but more importantly because 3/4 of the packets sent by my game are not in any way critical. The 1/4 that are critical, are hardly ever sent, compared to the other packets. TCP is only an option if the other two solutions that I’ve thought of absolutely suck.[/s]