Crossfire Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

TCP vs UDP



>>>>[From Eric A. Anderson]
    
    Philip Brown <philb@soda.berkeley.edu> writes:
    > [ largest amount of changes when lots of monsters ]
    > 
    > If they are getting updated here and there, let's say 10 pieces of
    > information in one packet, with tcp packet overhead, that generates a
    > hell of a lot of overhead.
    
    THe easiest way to deal with this is to batch up each of the packets
    which you conceptually send to the client.  Instead of sending a
    separate tcp packet for each update, you just keep putting data in a
    buffer, and when the server finishes processing a turn, it flushes all
    of the connections.

Exactly. Except Carl said he is firmly against the idea of "turns". Go
figure.

    > If you agrees to switch solely to UDP, I don't think I would have a
    > problem with this.
    I think this would be a mistake.  UDP means you have to repeat all of
    the work of transferring sequenced data; with all the chances of
    getting it wrong.  Why not just use TCP and take advantage of years of
    work?


I personally am not too worried about packets arriving out of order.

but for the paranoid,

You could always use absolute values in data, so out-of-order things
would soon be corrected.


Example1:
  server transmits that player has 10 out of 50 hp left, even right after
  a heal spell.  This will get corrected in the next packet or two that
  comes along. (we're talking about half a second here)

example 2:
  server transmits obsolete map data. obsolete, because player is no
  longer there. However, this wouldn't matter if:

#1 map data always is prefaced with WHICH map this data is for
#2 data comes in coordinates relative to the whole map, not the 11x11
     player area.

eg: player WAS at map coordinates 10,10, and receivs old data about that.

However, player is now at coordinates 20,20, and client automatically
ignores most of that data.


Besides which, even if we choose to put our own sequencing serial number
on packets.. even if the headers we tacked out got just as large as tcp
packets(and no way would we somhow add 36 extra bytes!!)
    UDP would still have one very important advantage.

TCP packets REQUIRE that the receiver acknowledge them.
 (not neccessarily for each one, but the requirement is still there)
UDP packets just go, and are forgotten about.

So when calculating required bandwidth to sustain a fast game with TCP,
you've also got to allow packet acknowledgement for TCP. This is what
makes for bad net lag (as opposed to just "mild" net lag with udp ;-)