# HTML5 Multiplayer Games over UDP (client/server) using geckos.io

**URL:** <https://forum.babylonjs.com/t/html5-multiplayer-games-over-udp-client-server-using-geckos-io/11436>\
**Category:** Demos and projects\
**Created:** [June 4, 2020, 9:01pm UTC](https://forum.babylonjs.com/t/html5-multiplayer-games-over-udp-client-server-using-geckos-io/11436 "2020-06-04T21:01:53Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![yannick](https://avatars.discourse-cdn.com/v4/letter/y/b782af/32.png) [@yannick](https://forum.babylonjs.com/u/yannick)\
**Post date:** [June 4, 2020, 9:01pm UTC](https://forum.babylonjs.com/t/html5-multiplayer-games-over-udp-client-server-using-geckos-io/11436/1 "2020-06-04T21:01:54Z")

</div>

![logo-256](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/e/ec4ab9f1d16ecb1dc94d30e6ebe5b61952f7d97e.png)

# [geckos.io](http://geckos.io)

I just wanted to [share a library](https://github.com/geckosio/geckos.io) 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](https://github.com/geckosio/geckos.io)! I’m sure some of you can use it 🙂

* * *

![logo](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/9/99b92d0b1c19b9fc9760dabcbd22471e26ca038a.png)

## Snapshot Interpolation

Also take a look at my [snapshot-interpolation](https://github.com/geckosio/snapshot-interpolation#readme) library for easily adding Snapshot Interpolation (also called Entity Interpolation or Buffer Interpolation) to your Games.

- **Snapshot Interpolation**
- **Client-Side Prediction** and **Server Reconciliation**
- **Lag Compensation**

---

<div class="post-metadata">

**Author:** ![wwwonka](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wwwonka/32/1781_2.png) [@wwwonka](https://forum.babylonjs.com/u/wwwonka)\
**Post date:** [June 5, 2020, 2:34am UTC](https://forum.babylonjs.com/t/html5-multiplayer-games-over-udp-client-server-using-geckos-io/11436/2 "2020-06-05T02:34:56Z")

</div>

Hey amazing work!  
So by using your library, one could build a **real-time** co-op game?!

Can I ask, since you’re using WebRTC, If you use a server to do the handshaking, then connect directly the 2 clients and let them exchange data in real-time?If so how is the latency looking like?

Since you’re using the DataChannel and unordered message over UDP, I bet that in a local environment, those are the best conditions to have as less latency as possible.

This is all of great interest for me as I am thinking of letting my player play my game on his tv/pc and use a phone as a controller, all of this connected through WebRTC.

I guess, simply put, my question is how is the real-time feel when using WebRTC and what’s the exact role of the server?

Anyways great to see your work!

---

<div class="post-metadata">

**Author:** ![yannick](https://avatars.discourse-cdn.com/v4/letter/y/b782af/32.png) [@yannick](https://forum.babylonjs.com/u/yannick)\
**Post date:** [June 5, 2020, 12:16pm UTC](https://forum.babylonjs.com/t/html5-multiplayer-games-over-udp-client-server-using-geckos-io/11436/3 "2020-06-05T12:16:23Z")

</div>

Glad you like it 😃

> [@wwwonka](#):
>
> So by using your library, one could build a **real-time** co-op game?!

Yes 🙂

> [@wwwonka](#):
>
> I bet that in a local environment, those are the best conditions to have as less latency as possible.

It was designed to be used on a server, but you can of course use it locally as well.

> [@wwwonka](#):
>
> I am thinking of letting my player play my game on his tv/pc and use a phone as a controller, all of this connected through WebRTC.

You mean using the tv/pc as server? You can run [geckos.io](http://geckos.io) in electron. So yes, if you ship your game with electron, it could host a [@geckos.io/server](https://www.npmjs.com/package/@geckos.io/server) instance.

> [@wwwonka](#):
>
> I guess, simply put, my question is how is the real-time feel when using WebRTC and what’s the exact role of the server?

[Geckos.io](http://Geckos.io) does the exact same thing as [socket.io](http://socket.io), but instead of using TCP it uses UDP. The gameplay feels a lot smoother via UDP. Of course if make a real-time multiplayer game, you will experience some lag due to package loss and others. But there is also a solution for this called [@geckos.io/snaphot-interpolation](https://github.com/geckosio/snapshot-interpolation#readme).

---

<div class="post-metadata">

**Author:** ![Raggar](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raggar/32/20672_2.png) [@Raggar](https://forum.babylonjs.com/u/Raggar)\
**Post date:** [June 5, 2020, 12:26pm UTC](https://forum.babylonjs.com/t/html5-multiplayer-games-over-udp-client-server-using-geckos-io/11436/4 "2020-06-05T12:26:21Z")

</div>

Looking nice. I’ll make sure to give it a try.  
It’s been a while since I played with WebRTC. Back then, there were issues with both Firefox and Chrome, resulting in only reliable connections being established at times. And the reliable configuration was not nearly as performant as WebSockets. On top of that, there were no precompiled versions for NodeJS, so installation on different environment varied and was at times tedious.  
Do you have any idea of the performance of running wrtc on NodeJS compared to WebSockets?

---

<div class="post-metadata">

**Author:** ![yannick](https://avatars.discourse-cdn.com/v4/letter/y/b782af/32.png) [@yannick](https://forum.babylonjs.com/u/yannick)\
**Post date:** [June 5, 2020, 12:49pm UTC](https://forum.babylonjs.com/t/html5-multiplayer-games-over-udp-client-server-using-geckos-io/11436/5 "2020-06-05T12:49:27Z")

</div>

> [@Raggar](#):
>
> Do you have any idea of the performance of running wrtc on NodeJS compared to WebSockets?

I don’t have any numbers. [Users tell me](https://github.com/geckosio/geckos.io/issues/21#issuecomment-614914089) that the benchmarks they made are excellent.

I will try make a simple 3d scene to compare WebSockets with [geckos.io](http://geckos.io). I will publish it here in the next days.

---

<div class="post-metadata">

**Author:** ![yannick](https://avatars.discourse-cdn.com/v4/letter/y/b782af/32.png) [@yannick](https://forum.babylonjs.com/u/yannick)\
**Post date:** [June 6, 2020, 10:42pm UTC](https://forum.babylonjs.com/t/html5-multiplayer-games-over-udp-client-server-using-geckos-io/11436/6 "2020-06-06T22:42:19Z")

</div>

I just made a one to one comparison between [geckos.io](http://geckos.io) and [socket.io](http://socket.io). Hope it helps 😃

[![](https://img.youtube.com/vi/ZEEBsq3eQmg/hqdefault.jpg "HTML5 Games - UDP vs TCP") ](https://www.youtube.com/watch?v=ZEEBsq3eQmg)

---

<div class="post-metadata">

**Author:** ![gbz](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/gbz/32/23780_2.png) [@gbz](https://forum.babylonjs.com/u/gbz)\
**Post date:** [June 7, 2020, 8:28pm UTC](https://forum.babylonjs.com/t/html5-multiplayer-games-over-udp-client-server-using-geckos-io/11436/7 "2020-06-07T20:28:21Z")

</div>

@yannick, this is groundbreaking! Thanks so much for creating the first working JS example (I’ve seen) inspired by Glenn’s UDP vs. TCP article’s examples.

Suppose we are using WebRTC and have no interest in peer-to-peer connections, but are only interested in client-to-dedicated-server connections (for a server-authoritative game). Since the dedicated servers will have public IPv4 addresses, will there be **zero need for STUN and TURN servers**? And Signaling servers are always required, but the dedicated server can also act as the Signaling server using WebSockets to communicate with clients?

Would be thankful for any guidance you could provide on this, @yannick 😃

---

<div class="post-metadata">

**Author:** ![Mr\_SquarePeg](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Mr\_SquarePeg](https://forum.babylonjs.com/u/Mr_SquarePeg)\
**Post date:** [June 7, 2020, 9:12pm UTC](https://forum.babylonjs.com/t/html5-multiplayer-games-over-udp-client-server-using-geckos-io/11436/8 "2020-06-07T21:12:48Z")

</div>

Hey @yannick - got a question - How well does Geckos scale across multiple cores and servers?

Just curious 🙂

---

<div class="post-metadata">

**Author:** ![yannick](https://avatars.discourse-cdn.com/v4/letter/y/b782af/32.png) [@yannick](https://forum.babylonjs.com/u/yannick)\
**Post date:** [June 7, 2020, 9:34pm UTC](https://forum.babylonjs.com/t/html5-multiplayer-games-over-udp-client-server-using-geckos-io/11436/9 "2020-06-07T21:34:47Z")

</div>

> [@gbz](#):
>
> will there be **zero need for STUN and TURN servers**?

I never made it work without a STUN server (there are many free once available). I have no idea if there are scenarios where a TURN server is needed. I would add a TURN server, track if someone needs it, and shut it down if it is not needed.

> [@gbz](#):
>
> And Signaling servers are always required, but the dedicated server can also act as the Signaling server using WebSockets to communicate with clients?

Yes, [geckos.io](http://geckos.io) handles the signaling itself (on port 9208 by default). It does not use WebSockets for the signaling. It uses http.

---

<div class="post-metadata">

**Author:** ![gbz](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/gbz/32/23780_2.png) [@gbz](https://forum.babylonjs.com/u/gbz)\
**Post date:** [June 7, 2020, 9:40pm UTC](https://forum.babylonjs.com/t/html5-multiplayer-games-over-udp-client-server-using-geckos-io/11436/10 "2020-06-07T21:40:45Z")

</div>

Thank you so much, @yannick!

---

<div class="post-metadata">

**Author:** ![yannick](https://avatars.discourse-cdn.com/v4/letter/y/b782af/32.png) [@yannick](https://forum.babylonjs.com/u/yannick)\
**Post date:** [June 7, 2020, 9:49pm UTC](https://forum.babylonjs.com/t/html5-multiplayer-games-over-udp-client-server-using-geckos-io/11436/11 "2020-06-07T21:49:27Z")

</div>

> [@Mr\_SquarePeg](#):
>
> How well does Geckos scale across multiple cores and servers?

I do not know if and how well it uses multiple cors. If we assume a multiplayer game with 16 players, I do not know if it make more sense to spin up a new geckos instance per game, or if it is the best to run only one geckos instance and use it for 10 games with a total of 160 players.

I really have not done any benchmarks of this kind yet. And really only a active multiplayer game will tell us which settings/options are the best.

I will, however, invest some time in the future to figure all of this out.

Hope it helps 🙂

---

<div class="post-metadata">

**Author:** ![yannick](https://avatars.discourse-cdn.com/v4/letter/y/b782af/32.png) [@yannick](https://forum.babylonjs.com/u/yannick)\
**Post date:** [June 19, 2020, 7:38pm UTC](https://forum.babylonjs.com/t/html5-multiplayer-games-over-udp-client-server-using-geckos-io/11436/12 "2020-06-19T19:38:59Z")

</div>

I just uploaded 2 videos for the Snapshot Interpolation library. A short and a long video. Hope you like it 🙂

- [Quick Introduction Video](https://youtu.be/-9ix6JxpqGo)
- [How to Use Video](https://youtu.be/ciNR4t-5-WI)

---

<div class="post-metadata">

**Author:** ![gbz](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/gbz/32/23780_2.png) [@gbz](https://forum.babylonjs.com/u/gbz)\
**Post date:** [June 19, 2020, 7:56pm UTC](https://forum.babylonjs.com/t/html5-multiplayer-games-over-udp-client-server-using-geckos-io/11436/13 "2020-06-19T19:56:42Z")

</div>

Amazing, thank you for your demo videos 😃

---

<div class="post-metadata">

**Author:** ![wwwonka](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wwwonka/32/1781_2.png) [@wwwonka](https://forum.babylonjs.com/u/wwwonka)\
**Post date:** [July 7, 2020, 2:50am UTC](https://forum.babylonjs.com/t/html5-multiplayer-games-over-udp-client-server-using-geckos-io/11436/14 "2020-07-07T02:50:16Z")

</div>

Hey yannick,  
Sorry for having been long to reply, my macbook died one day, all of a sudden, in the countryside of mexico while we were in the middle of a pandemic… But now it’s back.

> [@yannick](#):
>
> You mean using the tv/pc as server?

No! Apart from serving the files when my player downloads my game, my aim is to use no server at all and instead building everything thaught out for offline usage.

So basically if you play on a phone, you use touch controls and then if you happen to have a PC or a smart TV, you can either use a gamepad or use the very same phone as a controller connected by webrtc. Kind of the nintendo switch of the poors 😅

And so as long as the PWA or the website is opened on both device, the communication can happen, online or not. everything remains local. As signs of encouragements in this direction, I’ve stumbled across a few github projects that make WebRTC work without a signaling server:

> **[GitHub - pion/offline-browser-communication: Demonstration of a browser...](https://github.com/pion/offline-browser-communication)**
>
> Demonstration of a browser connecting to Pion WebRTC without a signaling server. - GitHub - pion/offline-browser-communication: Demonstration of a browser connecting to Pion WebRTC without a signal...

> **[GitHub - lesmana/webrtc-without-signaling-server: webrtc without signaling...](https://github.com/lesmana/webrtc-without-signaling-server)**
>
> webrtc without signaling server. a stun server is still used if connecting over the internet. - GitHub - lesmana/webrtc-without-signaling-server: webrtc without signaling server. a stun server is s...

Anyways, just wanted to share and thank you for the clues you’ve given here 🕶

Cheers!

---

<div class="post-metadata">

**Author:** ![gbz](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/gbz/32/23780_2.png) [@gbz](https://forum.babylonjs.com/u/gbz)\
**Post date:** [July 7, 2020, 6:31am UTC](https://forum.babylonjs.com/t/html5-multiplayer-games-over-udp-client-server-using-geckos-io/11436/15 "2020-07-07T06:31:39Z")

</div>

@wwwonka, hopefully our expert @yannick can offer some insight on this 😃

I read briefly through the second repo `webrtc-without-signaling-server`. It seems this demo did not require a signaling server, since the caller (user creating offer) and callee (user answering offer) both live on the same web browser `index.html` page. This would not work in either peer-to-peer or client-server situations. I think some form of signaling (some options being HTTP requests as mentioned by yannick, WebSocket, or even by pigeon mail 😛 ) is required for both of these scenarios.

---

<div class="post-metadata">

**Author:** ![wwwonka](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wwwonka/32/1781_2.png) [@wwwonka](https://forum.babylonjs.com/u/wwwonka)\
**Post date:** [July 8, 2020, 8:29pm UTC](https://forum.babylonjs.com/t/html5-multiplayer-games-over-udp-client-server-using-geckos-io/11436/17 "2020-07-08T20:29:31Z")

</div>

> [@gbz](#):
>
> I think some form of signaling (some options being HTTP requests as mentioned by yannick, WebSocket, or even by pigeon mail 😛 ) is required for both of these scenarios.

Yes you are right.  
I have been digging around those past few days and it seems like the signaling part is what’s gonna kill it. In the context of a local network, it seems all examples I have been able to find (and there’s not alot), the way of getting around without a server is to exchange ice candidates manually, or make use of qr codes.

And this is a multiple steps process. As in:

1. the first client acts as the initiator and sends its ice credentials **(by pigeon!)** to the 2nd client
2. the 2nd client pastes this in its browser, and sends back an answer containing his own ice credentials.
3. the initiator then pastes the answer on his side.
4. the connexion can occur.

This is very sad. I am really craving for a alternative and more elegant solution to this problem because even though this would technically work and, from my understanding, could even persist cross-sessions (meaning that it would only have to occur once per pair of device), it just murders the first impression. Even with QR codes this process would mean having to scan 2 of them, and one from each device. Big ugly ones as well.

Kind of off-topic but thaught I would share, in case someone has an insight about it.

---

<div class="post-metadata">

**Author:** ![morterra](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/morterra/32/25383_2.png) [@morterra](https://forum.babylonjs.com/u/morterra)\
**Post date:** [August 6, 2020, 3:14am UTC](https://forum.babylonjs.com/t/html5-multiplayer-games-over-udp-client-server-using-geckos-io/11436/18 "2020-08-06T03:14:52Z")

</div>

Awesome work!

This is one of the most beneficial libraries I’ve seen for browser games. An additional feature that may be beneficial for even outside of gaming is to add a clean way to implement UDP voice chat for Node.

Again, great work! I look forward to working with this in the near future!

---

<div class="post-metadata">

**Author:** ![yannick](https://avatars.discourse-cdn.com/v4/letter/y/b782af/32.png) [@yannick](https://forum.babylonjs.com/u/yannick)\
**Post date:** [August 12, 2020, 10:28am UTC](https://forum.babylonjs.com/t/html5-multiplayer-games-over-udp-client-server-using-geckos-io/11436/19 "2020-08-12T10:28:32Z")

</div>

[Geckos.io](http://Geckos.io) sends all traffic through a server, which will add latency to your audio and it is not cheap. A better option for voice chat would be a P2P WebRTC library (like [https://peerjs.com/](https://peerjs.com/) for example).

---

<div class="post-metadata">

**Author:** ![Egg](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/egg/32/10932_2.png) [@Egg](https://forum.babylonjs.com/u/Egg)\
**Post date:** [September 8, 2020, 8:25am UTC](https://forum.babylonjs.com/t/html5-multiplayer-games-over-udp-client-server-using-geckos-io/11436/20 "2020-09-08T08:25:38Z")

</div>

I did something similar with Peerjs, it comes out of the box with a free turn/ice server, but the principles are the same.

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [April 18, 2022, 7:47pm UTC](https://forum.babylonjs.com/t/html5-multiplayer-games-over-udp-client-server-using-geckos-io/11436/21 "2022-04-18T19:47:19Z")

</div>

I am loving all the great info about [geckos.io](http://geckos.io).

I am giving it a try as the default multiplayer game server implementation for the Babylon Toolkit over [colyseus.io](http://colyseus.io) (Which is a great lib… just no UDP)

According to Glenn Fiedler (The netcode guru) UDP is a must for **SMOOTH** realtime networking games.

Thanks @yannick 🙂

[Next page](https://forum.babylonjs.com/t/html5-multiplayer-games-over-udp-client-server-using-geckos-io/11436.md?page=2)
