[casual_games] standard practices in multiplayer gaming?

Bryan Wagstaff bryanw at xmission.com
Thu Sep 13 15:37:13 EDT 2007




>> Another thing to look for with setting up a multiplayer architecture is that packets are going to be lost or received out of order, very much like streaming video or sound. Your game needs to handle those elegantly (predictive algorithms on the client end)

> TCP ensures all packets will be received, and in the same order as in

> which they were sent (this makes TCP slower than UDP, but this is

> probably not an issue for most casual games).

>

> If you do want to use UDP, you indeed have to handle lost packets or

> packets received in a different order. The RTP protocol might help to

> implement a system to handle this (it wraps your UDP packets, adding

> information like a timestamp and sequence number).

>

The overhead of TCP is not noticeable most of the time. It only becomes
a problem when there are transmission problems (which you would have to
handle yourself under UDP) and on high latency high bandwidth
connections (like satellite broadband) which can have difficulty with
the sliding windows.

You also forgot some important details of UPD. First, UDP packets
almost always arrive in order and as expected (well above 99% of the
time). Second, you forgot to mention duplicates. Without your own
packet sequence numbers, the duplicate packets can kill you. UDP
packets look just fine for a long time -- potentially for countless
hours -- with a very rare stutter of duplicates, out-of-order, and one
or two lost packets all happening at once. Generally the stutter
happens when the network route changes, and that is a rare event on
dedicated connections.

Choosing your protocol has more to do with how you consider the network
than anything else. The "network as an event bus" model works extremely
well on UDP, much better than it does under TCP due in part to minimum
packet sizes. The "network as a streamed data" model can work well with
UDP for data with lossy properties. But "network as a serialized object
stream" is horrible under UDP, because of the amount of work you must do
to detect and correct transmission issues.


More information about the Casual_Games mailing list