Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Back in the day, TCP connections over dialup/ISDN/slow broadband resulted in choppy, laggy games because a single dropped packet resulted in a resync. That meant a lot of game developers had to implement their own reliability layer on top of UDP, or they used UDP for messages that could be dropped or received out of order, and used a parallel TCP connection for information that must be reliable.

Given the average user has faster network connections now, can a real time game such as an FPS give good performance over a TCP connection?

share|improve this question
add comment

8 Answers

up vote 30 down vote accepted

I would say no. Spacial information of game objects need to be as fast as possible, and for that it's better to use UDP, because reliability is not 100% crutial. Even on modern connections, UDP is still slow enough that you have to make some special considerations for interpolation and such. Even just in terms of the amount of data transferred, TCP would add significant overhead to this.

However, TCP is perfectly acceptable for non-realtime things, such as multiplayer negotiation, chat messages, score updates, etc.

share|improve this answer
7  
Sean is pretty much on the money. If, by chance, you are developing a game in C#/.NET (you know you want to!), I have found the Lidgren Network Library (code.google.com/p/lidgren-library-network) to be a pretty good choice. It even provides ordered, reliable messaging over UDP, should you need it. –  Mike Strobel Jul 16 '10 at 15:46
1  
It's unwise to mix both TCP and UDP; as a result of the way TCP performs flow control, it can induce packet loss. (source:isoc.org/INET97/proceedings/F3/F3_1.HTM) –  Jason Kozak Jul 16 '10 at 23:39
2  
It's also important to keep in mind that in some cases your end users will be sitting behind ISPs that block UDP traffic, have router setups that prevent UDP traffic, or otherwise are in a situation where using UDP is less than ideal. In those cases, if your game can support it, being able to fall back to TCP communication is quite handy. –  Charles Ellis Jul 19 '10 at 21:54
    
another + point for UD is that its naturally packet orientated, you have to emulate this in TCP if needed (boilderplatecode), sadly the more modern protocols are not supported by windows (this sucks) –  Quonux Apr 9 '13 at 18:20
add comment

As Flash doesn't support UDP, by looking at multiplayer Flash games you can get a pretty good idea of what's possible with TCP/IP and what isn't. Basically you can create real time games, as long as they don't rely on lightning-fast response times. A couple of examples:

http://www.xgenstudios.com/play/stickarena

http://everybodyedits.com/

If you have the option of using UDP, you really should, but with Flash you sadly don't get that option.

share|improve this answer
add comment

It depends.

Games like World of Warcraft use TCP for their communication, because you circumvent many problems by using it. There may be a higher ping as a result, but for many games, this is acceptable. You need to do spatial interpolation even when you use UDP as your protocol.

share|improve this answer
1  
It's not just ping. There's a reason why there is no player-player collisions in WoW. It would be too hard to do well. WoW can use TCP because where you are standing doesn't matter much. Targeting and attacking does not depend on the real position of the monster or enemy player. If you care about these things, then TCP will hurt the play experience. –  Nuoji Aug 14 '13 at 15:40
add comment

If your client/server architecture is clean, the transport layer (almost) doesn't matter.

TCP has some drawbacks, but these are easily cirumvented.

So yes, TCP and a brain is all you need.

With common network setups (proxies, firewalls, etc) today UDP is pretty much useless for all but local (read: LAN) games.

share|improve this answer
7  
If you downvote, please leave a comment why. We use TCP and never had a single issue with it. –  Andreas Jul 22 '10 at 14:58
2  
I fail to see the relevance of common network setups in this. Firewalls generally interfere with hosting servers only, but even then regardless of protocol, whereas proxies actually increase the risk of delayed or dropped packets, making UDP far more useful than it would be on a local network. UDP's drawbacks can largely be circumvented by doing integrity checks yourself, but you can't take features out of TCP to make it faster. –  Marcks Thomas Jul 17 '12 at 9:36
    
You need to mention Nagles. I always forget that's the root cause why TCP is evil (Nagle's buffers packets at client/server, basically "withholding" them from your game and introducing additional delay). –  bobobobo Apr 22 '13 at 19:59
    
There several reasons why you should use UDP instead of TCP if latency is a concern. If you don't care about latency and/or you're able to do enough client side prediction, then TCP can be enough. In the case of real time games. Forget TCP. –  Nuoji Aug 14 '13 at 15:36
add comment

For FPS games we always use UDP. Especially if you are doing a twitch shooter where pings matter.

share|improve this answer
add comment

Its perfectly acceptable to use TCP instead of UDP - if you turn off the Nagle's algorithm.

Once you turn off Nagle, you have most of the speed of UDP and will be fully able to make a twitch reaction game. Indeed, I have made such a game using TCP in Flash:

http://2dspacemmo.wildbunny.co.uk

Hope that helps!

share|improve this answer
    
Non-operational app at your link, sir. –  Nick Wiggill Feb 26 at 7:49
add comment

It depends on the kind of game.

Some games such as RTS, play much better over TCP and typically use TCP all the time.

The real problem with TCP is that if you get packet loss - even a small amount - then the connection "stalls" until retransmission happens. The OS can't deliver out-of-order data to the application (this breaks TCP's guarantees, but also, TCP does not show the application frame boundaries). The connection stall means that late data subsequently arrive. But in a (e.g.) FPS game, out-of-date data are useless.

With UDP, the application gets to choose what it does with late or out-of-order data. It can (and for a game such as FPS, usually does) ignore old data and just take the latest ones. An occasional lost packet doesn't delay subsequent packets at all. If a delayed packet eventually arrives, it can be ignored by the game.

share|improve this answer
add comment

I don't think so... Games where data transfer is very frequent (on mouse-move or key-down), should use UDP. It'll lag even on LAN if TCP is used.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.