WebRTC really isn't suitable for multiplayer gaming due to it being entirely P2P. You need the server to operate as a single source of truth and enforce clients to play by the rules.
TCP from a master server to every client. and UDP low latency links from every client to every other client. The client code sends a sample of received UDP packets to the server over the TCP connection, who will then verify that all info contained in the packets is true and accurate and nobody was cheating. It's a nice model because you get the super low latency between clients, and at the same time within a few hundred milliseconds you can detect cheaters and kick/ban them. Obviously, you have to design your game to handle asynchronous lossy information from many different sources and nobody having a complete and whole view of the game until half a second later or so. Thats quite do-able though by timestamping every event and then running rollback-able or checkpointed synchronous simulation on all clients.
When a packet is lost in a TCP stream, it must be retransmitted, and until the client receives it, all further packets are stuck in limbo (received by the client, but cannot be seen). For this reason, most games use UDP instead, and are designed so some packet loss is acceptable (if I received where you are at frame N, it no longer matters if I receive where you were at frame N-1). Minecraft uses TCP, that's why in very populated servers occasionally you can see the whole world freeze for a second. In the browser we have UDP with WebRTC data, the problem is that not all browsers support it, it may not work in some places and for now it's more difficult to work with. An easy compromise is to use several TCP connections, so if one packet is lost, instead of having N packets stuck for a moment, you have 1/N where N is the number of connections. And if important packets are sent through all channels, the chance that they arrive too late is much lower.
There's also another important detail. Due to delayed ACKs on Windows and battery-preserving TCP stacks on most mobile devices/laptops, some of your packets will be delayed. Even with TCP_NODELAY. Desktop OSX/Linux do not display this behavior. The only solution I have found, and it's a rather crude one, is to blast the server every 50ms with a 1-byte packet. It is ugly but it works well.
Comments (304) 119 threads
Earlier commentsSome gameplay footage: https://www.youtube.com/watch?v=LiO6XYt8M14&list=PL192CF249E...
Large list here: http://iogames.space
Continue this thread — 1 reply
TCP from a master server to every client.
and
UDP low latency links from every client to every other client.
The client code sends a sample of received UDP packets to the server over the TCP connection, who will then verify that all info contained in the packets is true and accurate and nobody was cheating.
It's a nice model because you get the super low latency between clients, and at the same time within a few hundred milliseconds you can detect cheaters and kick/ban them.
Obviously, you have to design your game to handle asynchronous lossy information from many different sources and nobody having a complete and whole view of the game until half a second later or so. Thats quite do-able though by timestamping every event and then running rollback-able or checkpointed synchronous simulation on all clients.
Continue this thread — 1 reply
I use 2 WS connections mirroring some packets on both, to deal with head-of-line blocking.
Continue this thread — 18 replies
When a packet is lost in a TCP stream, it must be retransmitted, and until the client receives it, all further packets are stuck in limbo (received by the client, but cannot be seen). For this reason, most games use UDP instead, and are designed so some packet loss is acceptable (if I received where you are at frame N, it no longer matters if I receive where you were at frame N-1).
Minecraft uses TCP, that's why in very populated servers occasionally you can see the whole world freeze for a second.
In the browser we have UDP with WebRTC data, the problem is that not all browsers support it, it may not work in some places and for now it's more difficult to work with.
An easy compromise is to use several TCP connections, so if one packet is lost, instead of having N packets stuck for a moment, you have 1/N where N is the number of connections. And if important packets are sent through all channels, the chance that they arrive too late is much lower.
Continue this thread — 2 replies
There's also another important detail. Due to delayed ACKs on Windows and battery-preserving TCP stacks on most mobile devices/laptops, some of your packets will be delayed. Even with TCP_NODELAY. Desktop OSX/Linux do not display this behavior.
The only solution I have found, and it's a rather crude one, is to blast the server every 50ms with a 1-byte packet. It is ugly but it works well.
All comments shown.
Couldn't load more comments. Check your connection and try again.