I just wanted to share a library I built a while ago. I read a lot, even in newer posts, that networking over UDP is not possible in the browser. But it is possible. WebRTC’s DataChannel can send unordered and unreliable message via UDP (SCTP). But WebRTC does not only work in browsers. It works, amongst other things, on Node.js. So if you want to network your multiplayer game over UPD, use WebRTC on the browser and on node.js.
That’s exactly what my library does. Sending client/server messages via UDP between browser and node.js. Take a look! I’m sure some of you can use it
This is a copy paste of a topic I just created in the babylon.js forum. But I feel like it fits also just perfectly in here.
Nice! Can you please give a bit more detail about differences between websockets and WebRTC? (unless they are the same, I’m kinda ignorant with networking. I just recall Colyseus framework used ws:// for real-time communications and HTTP for ordered updates.)
The big difference between WebSockets and WebRTC is that
WebSocket runs on top of TCP
WebRTC’s DataChannel runs on top of UDP
What this can mean for you multiplayer game, you can watch here.
I just saw that there is one related open issue and one that got closed. Maybe they will add it someday. Maybe I could write to them and help them add it. I have no idea what their plans are
Good job, I believe it will help me a lot in my mmorpg project, I had doubts about the websocket and you touched on an important point, UDP or TCP, thanks for sharing!
This is sick! Never thought that the web will ever support UDP. This is going to fix all those lags we have in those fun little web games. Amazing work!!
Awesome showcase! You should definitely put it up on geckos.io readme, showcasing the difference between UDP and TCP (or between geckos.io and socket.io). Nothing is quite as convincing as a clear visualization
Bad network, I guess. I’m not really a networking pro and do also not have any statistics about package loss. Would be great to see some per country based statistics.
But package loss is not the only thing geckos.io protects you. It smooths out huge latency spikes.
Below an packetlosstest.com screenshot taken from my phone. Where I live, package loss seams not to be an issue, however some packages arrived with 100ms (or more) delay.
Now, imagine you send every 16ms (60 times per second) a new update to your client and the 100th package has a delay of 100ms. Even though you may already have received packages 101, 102 and 103, if you use TCP, the client will have to wait for package nr. 100 before it can read 101, 102 and so on. If you use geckos.io (UDP) you can instantly read 101, 102 and drop 100 when it arrives.
For the future I see that we can play with QUIC/HTTP3 as an experimental feature for now:
firefox > about:config > http3 > network.http.http3.enable > true
chrome > chrome://flags/ > quic > experimental quic protocol > enable