Besides saving bandwidth, I don’t get why people would like to use TCP for any fast paced action game. I know thats a bold statement given the amount of discussion on this and yes i’ve read through the whole TCP VS UDP thread. But hear me out
Typically you’d have two kinds of messages in your game; ones that need to be send reliable and ones that you should fire and forget about. In most fast paced multiplayer action games, you typically have objects that are controlled by remote players but which behaviour is difficult to predict, be it because of a high degree of freedom in movement etc. To be able to make an accurate prediction as possible of their behavior, we need a high as possible update rate of their current state. We need to forget about resending a lost packet as these would already be outdated when they arrive, we need to go on. Unfortunatly thats impossible because the way TCP is built, so UDP is clearly needed for that purpose.
Of course we still have the need for reliable messages and TCP was build just for that purpose. I also agree TCP performs just as well in the same environment as UDP and does a better job at delivering reliable messages than any reliable UDP protocol ever could, because TCP is implemented in hardware. So you could go and built something that uses UDP for the highrate updates and TCP for reliable messages. But using TCP and UDP together has some potential problems:
- TCP doesn’t work with the UDP NAT punch through technique.
- In certain situations (typically on narrow channels like modems or a slow DSL uplink), TCP can interfere with the UDP protocol layer, causing jitter in receiving UDP packets.
- Using two protocols forces you to make two different outgoing/incoming connections and handle two different types of incoming messages, which probably means you’ll have to design your game to take this in account. This point is more of a design question though.
Now, it’s also possible to implement a reliable protocol using UDP. But this needs a solid design designing and massive amounts of testing to get working properly. Also using reliable UDP will probably give slightly less performance to TCP, but this is often not needed for the reliable messages and we’d talk about a very small amount here. But going with reliable UDP would prevent the all potential problems pointed out above. Also, there are already are some quite solid reliable UDP libraries around, even one ported to Java as I pointed out before (jEnet) which will save you this trouble.
Now I think this holds up only for games with fast interaction between players, TCP is probably a better choice when you don’t need that (because the internet is mostly build around TCP like mentioned before). Herkules Flying guns is a very good example that even a flight simulator can be done using TCP, deadreckoning on the aircraft works quite well I guess as their motion is pretty limited?
Thijs