🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Joining data to bigger UDP packets?

Started by
10 comments, last by hplus0603 8 years, 3 months ago

where does the 1272 come from


The minimum fragment size for an IP packet on IPv6 is 1280 bytes. UDP uses 8 bytes for its header, leading 1272 bytes for the payload.

In UDP, the call to recvfrom() will return the exact size of the UDP packet payload (assuming your receive buffer is big enough,) so you don't need to encode that. This is in difference to TCP, which returns "some bytes" when you call recv(), and those bytes may be the end half of one packet and the beginning half of the next, so you need to implement an explicit packet framing protocol.

When you put multiple smaller game messages into a single UDP packet (which you absolutely should do!) then you have to have some way of knowing how many of those messages there are. If each message is fixed size, this is easy. If not, you'll need to encode the length of each sub-message; typically with a byte per message (as almost no individual game messages are > 127 bytes in size, and you can use the leading bit for var-int type encodings.)
enum Bool { True, False, FileNotFound };
Advertisement

If you run on a really crappy network implementation...

...which at least 10% of people-on-the-Internet usually have... And each time I'm trying to connect from a hotel - I'm learning new horizons of "what 'really crappy' can possibly mean" :-(.

FWIW: Google (I think in QUIC paper) has reported that 6-9% of the people-who-have-TCP can't get UDP at all (MIGHT be because of 3rd-world countries, but I'm not 100% sure - might be hotels/work firewalls/...). In any case, fallback to TCP (if the game still stays "somewhat playable") still sounds as a Good Idea - and then the whole question "where exactly to cut UDP size" becomes much less important.

each time I'm trying to connect from a hotel - I'm learning new horizons of "what 'really crappy' can possibly mean" :-(


Tragedy of the commons.
Local burner pre-paid USB modem fo' life, yo!
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement