TCP vs. UDP

While looking at the api documentation in SDLnet.h, I decided I’d ask
other opinions on this. Why would one choose UDP over TCP (or
vice-versa) game networking?

I do understand some of the differences between the two protocols… UDP
isn’t guaranteed, it is connectionless, sends data grams, etc…

The chatd example appears to use TCP to communicate with the server and
UDP to communicate with the other chat clients.

Do people tend to use UDP for situations where there are many more
destinations to send data to… and TCP for a single dedicated
client/server type connection?

I notice UDP is used with lots of ‘client’ type games, where data is
sent between many clients… (I think many of the popular 3D shoot’em’up
games use UDP??)–
Brian Hayward

While looking at the api documentation in SDLnet.h, I decided I’d ask
other opinions on this. Why would one choose UDP over TCP (or
vice-versa) game networking?

The short answer is that TCP is optimized for throughput for things like
file transfer – at the cost of latency. These optimizations (flow control,
Nagle’s algorithm) are not suited for realtime network games. It’s not to
say that UDP is “better”, it just provides lower level tools. You can build
on reliability, multicasting, etc, at the cost of throughput, but it’s easy
to make something with UDP that’s slower/less reliable than TCP. It really
depends on your needs.

The long answer can be found at my (informal) website:

http://www.codewhore.com

Matt±-------------------------±----------------------------------+
| Matt Slot | Ambrosia Software, Inc. |
| Bitwise Operator | http://www.AmbrosiaSW.com/ |
±-------------------------±----------------------------------+

UDP has less overhead than TCP Most online realtime game slike Quake use it
because it hs a faster response time. hope that helps.
Jess Haas (@Jess)

hayward at slothmud.org wrote:> While looking at the api documentation in SDLnet.h, I decided I’d ask

other opinions on this. Why would one choose UDP over TCP (or
vice-versa) game networking?

I do understand some of the differences between the two protocols… UDP
isn’t guaranteed, it is connectionless, sends data grams, etc…

The chatd example appears to use TCP to communicate with the server and
UDP to communicate with the other chat clients.

Do people tend to use UDP for situations where there are many more
destinations to send data to… and TCP for a single dedicated
client/server type connection?

I notice UDP is used with lots of ‘client’ type games, where data is
sent between many clients… (I think many of the popular 3D shoot’em’up
games use UDP??)


Brian Hayward

While looking at the api documentation in SDLnet.h, I decided I’d ask
other opinions on this. Why would one choose UDP over TCP (or
vice-versa) game networking?

The short answer is that TCP is optimized for throughput for things like
file transfer – at the cost of latency. These optimizations (flow control,
Nagle’s algorithm) are not suited for realtime network games. It’s not to
say that UDP is “better”, it just provides lower level tools. You can build
on reliability, multicasting, etc, at the cost of throughput, but it’s easy
to make something with UDP that’s slower/less reliable than TCP. It really
depends on your needs.

The long answer can be found at my (informal) website:

http://www.codewhore.com

Wow, nice site. :slight_smile:

-Sam Lantinga				(slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec

wow, very informative site. Looks like I came to the right place :slight_smile:
–BrianOn Wed, 22 Dec 1999, Matt Slot wrote:

While looking at the api documentation in SDLnet.h, I decided I’d ask
other opinions on this. Why would one choose UDP over TCP (or
vice-versa) game networking?

The short answer is that TCP is optimized for throughput for things like
file transfer – at the cost of latency. These optimizations (flow control,
Nagle’s algorithm) are not suited for realtime network games. It’s not to
say that UDP is “better”, it just provides lower level tools. You can build
on reliability, multicasting, etc, at the cost of throughput, but it’s easy
to make something with UDP that’s slower/less reliable than TCP. It really
depends on your needs.

The long answer can be found at my (informal) website:

http://www.codewhore.com

Matt

±-------------------------±----------------------------------+
| Matt Slot | Ambrosia Software, Inc. |
| Bitwise Operator | http://www.AmbrosiaSW.com/ |
±-------------------------±----------------------------------+

hayward at slothmud.org wrote:

While looking at the api documentation in SDLnet.h, I decided I’d ask
other opinions on this. Why would one choose UDP over TCP (or
vice-versa) game networking?

Only one reason: speed.

I do understand some of the differences between the two protocols… UDP
isn’t guaranteed, it is connectionless, sends data grams, etc…

The chatd example appears to use TCP to communicate with the server and
UDP to communicate with the other chat clients.

Do people tend to use UDP for situations where there are many more
destinations to send data to… and TCP for a single dedicated
client/server type connection?

The answer is yes, because UDP supports multicasting, while TCP does
not. TCP is typically used where a single connection is necessary, and
guaranteed delivery is also necessary. TCP does a very efficient job of
implementing what it does, but in certain situations the performance is
not acceptable and the features aren’t entirely necessary. One example
of this is voice-over-IP; a VoIP application can re-assemble datagrams
in the correct order on its own, and complete delivery is not totally
necessary, since performance is allowed to degrade gracefully with the
bandwidth constraints.

I notice UDP is used with lots of ‘client’ type games, where data is
sent between many clients… (I think many of the popular 3D shoot’em’up
games use UDP??)

Yep, because of speed.

MJP

http://www.codewhore.com

Wow, nice site. :slight_smile:

Hey! I was gonna say that! :wink:

-bill!

I notice UDP is used with lots of ‘client’ type games, where data is
sent between many clients… (I think many of the popular 3D shoot’em’up
games use UDP??)

I am currently writing a fast-action network game. I am using a
combination of the two where UDP is used to get a reasonably accurate
version of the time as the server knows it and to send some less
important data (like player ship stat updates and secondary object info)
that doesn’t really affect playability if the packets don’t get to
the other side. TCP is used to send player input to the server and
to send more important data to the client. If there is too much
packet loss in the UDP path, the server can be instructed to prefer
TCP for the client in question.

I think that, since the protocol I’m using sends packets of max. 64 bytes
at a time, it would be better to write a more packet-oriented protocol
on top of UDP so that one could assign packets a deadline and a
priority so that more important data will get across first and packets
could be removed from the send queue when there is newer, more up-to-
date info available. I’ve never gotten around to implementing such
a thing; perhaps some day…

The more popular 3D FPSes typically use a semi-reliable protocol on top
of UDP. This is because TCP isn’t very good for fast action as it tends
to increase the “ping time” to unacceptable values, even on
comparatively fast links.On Tue, Dec 21, 1999 at 11:58:01PM -0600, hayward at slothmud.org wrote:


Kalle A. Sandstr?m ksandstr &at& saunalahti &dot& fi
MY?K MY?K * [psilon @ IRCnet]
http paksusuoli 2x-viilto www piste sci piste fi viilto mato ksandstr
* torakan naurua
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/19991222/043b3e71/attachment.pgp