5 ms·
I'd have to agree with the "yet" part, but most of the article wasn't very good advice. If you're getting started with multiplayer game code, you should be fin
by exDM69 13y ago
I'd have to agree with the "yet" part, but most of the article wasn't very good advice.
If you're getting started with multiplayer game code, you should be fine with TCP for starters. Early in the project, most of the connections for testing will happen over a loopback interface and LAN anyway.
However, if you're doing a real time multiplayer game, you can't ship with TCP or your reputation (and sales, etc) will be ruined. No-one likes laggy gameplay.
In the above, I use the term "real time" as in a "soft real time software system", not real time as opposed to a turn based game. In other words, "real time" in the sense that if significant latency occurs, the game will produce incorrect results.
Arguably, most games do not fall under this category. E.g. a real time strategy game server has the option to "stop the world" and wait for all players to get back in sync. They are essentially very fast turn based games when it comes to analyzing it as a software system.
This means that most games can probably use TCP.
If you can't survive one second of latency, you must use UDP. You can bootstrap your project on TCP, but you can't use it over real networks.
> When everything is working perfectly and there is no packet loss (assuming Nagle is disabled), UDP and TCP will perform approximately equivalently; data gets through immediately, it's delivered to the application, there's no need to retransmit.
This is important, both ways. When everything works correctly, either one will do. But in real world, everything doesn't work always smoothly. You won't know if your network code works well before you've tried it with several players across the world. On the other side of town is not far enough.
> And on most modern consumer networks, packet loss is very low.
This is true only if you measure using "ping" in a network with no contention. That is not a real world measurement.
In most consumer networks, the WAN throughput is smaller than LAN, so if you have several computers hooked up, the router will have to drop some packets if everyone attempts to send or receive at their maximum capacity.
Go play Counter Strike and have your little brother turn on a BitTorrent service or your wife watching movies on NetFlix. Packet loss will occur.
> You may never even see the conditions where UDP should be faster.
It is not about being faster. The throughput of TCP should be pretty much equal to UDP when you average over time. The pings should be similar most of the time.
It's all about latency. A single lost packet on TCP will inhibit all the packets sent after it until the situation is lost. This can be one second or more, regardless of the quality of the connection in ideal conditions.
The bottom line is: know whether you will need UDP or not. Do not guess, measure and test it in real world networks. But you can still use TCP to bootstrap your project.
Regardless whether you use TCP or UDP your network game must have a mechanism for dealing with latency, like stopping the world in an RTS game (over TCP) or predicting the movements of characters in an FPS game (over UDP). TCP does not magically solve all the problems in networking, it also creates some.
- danielweber 13y agoI like to ask "why is UDP perfect for VoIP calls?" A packet showing up a second late is completely worthless. You don't want it at all. If the connection gets interrupted, well, it gets interrupted, and the people using it have to repeat themselves. But this beats hearing words (as if you would be so lucky as to have each word be its own packet) out of order.
- roc 13y agoLate packets aren't always completely worthless. a "late" rocket_fired type of packet can be very useful if it still shows up before the next packet that refers to said rocket. It really depends.
- bradleyland 13y agoVoIP protocols are designed to expect the exact condition described here; i.e., packets out of order and variation in the rate at which packets are received. A buffer is used to account for volatility in network latency. The size of this buffer is one of the more important problems that must be solved when implementing VoIP. See also: http://en.wikipedia.org/wiki/Jitter http://en.wikipedia.org/wiki/Jitter http://en.wikipedia.org/wiki/Jitter#Jitter_buffers http://en.wikipedia.org/wiki/Jitter#Jitter_buffers
- TrainedMonkey 13y agoBecause voice and language have so much redundancy built in that dropping few packets will not degrade perceived call quality. On the other hand, waiting a quarter of a second to receive lost packet definitely will degrade call quality.
- deleted 13y ago[deleted]
- arnehormann 13y agoTCP and UDP use the same underlying wire and the same hardware. If UDP would lose a packet or it would arrive late, the same could happen to TCP. TCP will retransmit and you lose a little bandwidth. But in both cases, you can't use the late data anymore - audio has about the hardest timing restrictions you can have when dealing with humans. Lateness means forced loss. TCPs ACK packets don't help there either, you want to keep down latency because your data can not be used any longer if it's dropped or late. Reliability becomes increasingly irrelevant, latency is everything.