Reliable UDP

Started by
2 comments, last by Kensai 23 years ago
I''m kicking around how to do reliable communications over UDP and wanted some pointers. First, I wanted to get a maximum _practical_ message size (one post said 576 bytes, I believe? -- I know the max allowable limit is more like 4k but I want to make sure the messages will arrive as reliably as possible) and know if there are any resources out there that cover this kind of thing. I''ve searched here and on Gamasutra and haven''t come up with much that''s applicable. Really what I need is information on how best to implement a fairly reliable protocol over UDP. I figure periodic resends until either a timeout or a "recieved" reply arrives, but that''s just the most straightforward solution. Speed is not as critical as in most multiplayer games, but TCP is still not a practical solution due to number of clients, etc. Sean
Advertisement
Oops... I just increased my date window size and ran scross the thread from about a week ago. Sorry about the repost :p


Sean
If you want to have reliable udp you have to do a number of things to make it more like tcp. Tcp is built on top of datagrams since the tcp/ip protocol is packet-based and tcp is a streaming protocol while udp is message based. Yourll need a sequence number on each of your packets, and reorder them on the client/server side. Yourll need to check the maximum transmission unit (in the WSAData from the WSAStartup or something call) for datagrams. If your using linux there is a system call that can do this too. You can only send when the socket is writeable from your select() or message loop FD_WRITE stuff. And, yourll need to resend packets if you dont get an acknowledgement of their receival.

Note though, that checking the MTU (max transmission unit) is usually unnessasary, the tcp/ip protocol standard has a minimum of about 512 of a mtu. If your o/s kernel cant do that, it will fragment and reassemble packets automatically (i think). Since your creating a game where events are time critical, id suggest keeping your packets under 64 bytes so you will have as lesser stress on your network as possible. That will reduce packet droppage, but its possible for busy routers to randomly drop packets so you will need a reliable ack/reply system.

CorsairK8@Fnemesis.comLinux Debian/GNU RulezThis is my signitory!C Is Tha Best!
Yes, IP packets _should_ be fragmented and reassembled. However, I heard some weird rumours about packets >1,5KB (?) not being handled correctly by some 56k modems some of the time. This is all very fuzzy information of course

The theoretical maximum of an IPv4 packet is just under 64KB (it''s 64KB including the header, which is at >=20bytes).

cu,
Prefect

Resist Windows XP''s Invasive Production Activation Technology!
One line of sourcecode says more than a thousand words.
Widelands - laid back, free software strategy

This topic is closed to new replies.

Advertisement