3 ms·
Games like agar.io and slither.io use websockets over TCP because browsers don't allow you to use UDP packets. The author of one of them (sorry I forget which)
by penagwin 8y ago
Games like agar.io and slither.io use websockets over TCP because browsers don't allow you to use UDP packets. The author of one of them (sorry I forget which) blogged about their adventure, and IIRC they still have lag issues, and there isn't a way to resolve them without switching to UDP.
I've personally worked on multiplayer game engine code and I assure you that UDP is far superior for VOIP and game state packets. TCP requires far too much overhead, requires packets be received in order, etc.
These make no sense for a game engine. If we have a sequence of player movements, lets say their X position [1, 2, 3], but we miss a packet [1, -, 3] we're fine, we only want their most recent packet. But the protocol will require acknowledgment and that packet to be resent, so it will require 8 different packets be sent, instead of 3! We don't even need the packet!
A lot of games are implementing web based technologies for their UIs (Panorama for example) and those will of course use TCP but that's not what the actual game server uses for VOIP/game state
- jondubois 8y agoAgreed. For most fast paced multiplayer games, UDP would be better. It depends on the specific use case though. TCP has some advantages when you need features like authentication and encryption because packets are guaranteed to be delivered in-order for the life of the connection; this feature is important for TLS block ciphers. With UDP, you may end up having to reinvent some features that are already offered by TCP and your solution might end up worse overall. So you have to find the balance between code simplicity and performance. TCP can cover more use cases than UDP but for some use cases this will be at the expense of performance.