TCP or UPD

BlitzMax Forums/BlitzMax Programming/TCP or UPD

Triforce Guardian(Posted 2006) [#1]
I was just wondering which protocol is better TCP or UPD. I hear TCP is slower than UPD and in some places I hear TCP is much better than UPD. I'd figure somebody at these forums would know which is the best to use for a online multiplayer game.


Cajun17(Posted 2006) [#2]
Depends on the type of multiplayer game. UDP is indeed faster than TCP, but it has several disadvantages.

1. UDP isn't as secure as TCP.
2. TCP packets always show up in the order they were sent, UDP packets may or maynot always arrive in the proper order.
3. UDP packets aren't identified in any way so you have to put some kind of id in the packet.
4. UDP packets don't always arrive at all.

Unless you know you need every drop of speed, like of r a FPS game, the speed gained from using UDP isn't worth the trouble. There are some libraries built on UDP that help take care of those problems, i.e. racknet.


Zumwalt(Posted 2006) [#3]
My theory on tcp vs udp:
tcp <= 32 player network
udp > 32 player network

You need to learn how to build in a 'latency' node for your games, engines like rakknet have this type of checking built in.

Player A is running and shooting, udp packets are flying around, player Z's packets are arriving slowly and they are also running and shooting, player A's packets are snap on target. What does this mean for udp? The packets are lost, however, the player Z character's checking algorithim states that X amount of packets are ok to loose, in the mean time player Z will continue along his current path of travel with last known command for up to X amount of seconds until he just stops in his tracks and doesn't do anything until the next real packet for player Z arrives successfuly.

With TCP, you are stating you want to guarantee the packet always arrives, this is why things slow down a bit and you get 'lag' spikes, because with a tcp network engine, your engine will attempt to resend any packets the server see's it lost.

Another vision on it, use TCP when dealing with file uploads / downloads do to the simple fact, like a pdf for instance, you don't want the recipient to miss out on getting 1 byte of information, hope this helps.


Regular K(Posted 2006) [#4]
Generally, speed oriented needs go UDP. Accuracy oriented needs go TCP.

Most games are UDP because of the speed, but if you're doing a turn-based game, TCP might be better. For some type of file server, TCP is the way to go.


bradford6(Posted 2006) [#5]
you have both. use both

UDP is unreliable (it does not do error checking)
TCP is reliable (i.e resends dropped packets)

use TCP to send periodic file updates, maps, etc

use UDP for real time stuff (like voice communication)

the type of update will really depend on the game.

do you send the LOCATION (X,Y) of the object each frame

Do you send the VECTOR (a direction and a speed) and let the recipient PC figure out where to place the object.

do you send a MOVE (in chess for instance "Black Queen to B4") and let both PC's smoothly move the pieces.


Triforce Guardian(Posted 2006) [#6]
Thanks guys for all the help. Now all I need to do is write a client and server.


LineOf7s(Posted 2006) [#7]
...all I need to do is...

HA! :o)


Triforce Guardian(Posted 2006) [#8]
lol...random.