Quote:
Well I would use UDP but TCP is better for games, right?
It depends on the game.
Turn based strategy games can get away with it. I've also heard that world of warcraft uses TCP. But in general, action games use UDP.
Often, they build a reliability layer on top of UDP. This is why I suggested researching some high level libraries to handle the networking for you.
TCP tends to have a higher latency than UDP, because it must act like a stream. If you send 10 UDP packets and the middle one is lost, you will receive 9 packets at the end point. If TCP sends 10 segments and the middle one is lost, even if the others arrive they won't be delivered to the application until the lost one is successfully retransmitted.
This leads to artificial latency, which can be made worse if the data doesn't need to be 100% reliable anyway. In a game, the latest packet is usually more important than earlier ones, so it doesn't usually make sense to have these buffered somewhere waiting for an earlier packet to arrive.
The other thing is that TCP tries, as the name suggests, to control congestion in the network. It limits the amount of data it will have on the network. If it detects packet loss it will lower this limit. This can result in data being buffered on the sending machine, waiting for the receiver to signal that they can handle more data or for the network to allow packets through. This can cause further delays, in addition if the local buffer is exceeded your program will block on a send() call.
It might be interesting for you to look at how other games handle networking, for example, Quake 3 or Unreal.