Using UDP in the Browser for faster Client/Server Connections

Rate this content
Bookmark
Video Summary and Transcription
The video explores the use of Geckos.io, focusing on real-time client-server communication over UDP in browsers. It highlights the benefits of using WebRTC and Node.js for faster connections, especially in multiplayer games. Geckos.io is designed for efficient UDP communication, making it ideal for applications needing high-speed data transfer. The talk explains how UDP is used in HTML games to enhance performance, and how JavaScript UDP plays a crucial role in enabling these interactions. Additionally, the importance of Web UDP is discussed, showcasing how it facilitates seamless browser-server connections. The speaker provides insights into deploying Geckos.io, including the necessity of opening UDP ports and handling signaling. The video also touches on alternatives like WebSocket and WebTransport for different application needs, emphasizing the flexibility of Geckos.io in various scenarios.

This talk has been presented at JS GameDev Summit 2023, check out the latest edition of this JavaScript Conference.

FAQ

Besides geckos.io, Janik has developed several other projects including Enable3D, a wrapper around 3js and AmmoJS; EnableJS, a simple JSX library; Fiveserver, an enhanced version of the Live Server NPM package; and html2app.dev, a service converting HTML apps to native apps.

Geckos.io is best suited for real-time applications like multiplayer games with an authoritative server. For applications requiring less real-time interaction, such as turn-based games, other technologies like WebSocket or HTTP requests might be more appropriate.

Geckos.io was developed by Janik, who started the project to enable UDP communication in the browser for multiplayer games. He identified the need for faster client-server connections which were not possible with existing technologies, leading to the creation of geckos.io.

Geckos.io is a library designed for real-time client-server communication over UDP using WebRTC and Node.js. It facilitates the establishment of a direct browser to Node.js server UDP connections, primarily intended for real-time multiplayer games and other applications requiring high-speed data transfer.

In geckos.io, the server handles the signaling between itself and the client. The server IP must be public so that clients can directly connect to the server via WebRTC data channels. Signaling is done on the server, and clients connect directly to the server, bypassing any load balancers for the UDP traffic.

To deploy geckos.io, you need to open UDP ports on the server as the communication uses UDP for data transmission. It's not suitable for deployment on services like Heroku that do not allow opening of UDP ports.

Alternatives to geckos.io include WebSocket for TCP-based communication, and upcoming technologies like WebTransport, which will support HTTP/3. These provide different trade-offs in terms of reliability, setup complexity, and how they handle network intermediaries like load balancers.

Users often face challenges with deployment, especially in environments where UDP ports cannot be easily opened or configured, such as on certain cloud platforms. Additionally, integrating with load balancers can be tricky as UDP traffic must bypass these.

1. Introduction to geckos.io and My Background#

Short description:

Hello and welcome to my talk about geckos.io. I will quickly tell you about myself and then show you more about geckos and make a demo using it. I did a lot of software and DevOps in the past. Now I'm working as a web dev teacher at a school. I have published several libraries, including geckos.io, Enable3D, EnableJS, Fiveserver, and html2app.dev. Currently, I'm teaching WebDev and maintaining some commercial products. The only library I use a lot is Nano.jsx. Let me quickly show you Enable2D, Nano.jsx, and HTML2 app.

Okay, so hello and welcome to my talk about geckos.io. My name is Janik and this here is my GitHub profile, in case you're interested. I will quickly tell you some things about me and then I will show you more about geckos and make a demo using geckos.

Okay, so I did a lot of software and DevOps in the past. Now I'm working as a web dev teacher at a school very close to where I live. It's a lot of fun, a lot of students. I have around 80 students. It takes a lot of time but it's really fun. I did a lot of free and open source work in the past. The one, my first big library I published was geckos.io, which I will talk about today. Then we have Enable3D which is a wrapper around 3js and AmmoJS. Then another EnableJS, a very simple JSX library. Then we have Fiveserver, which is a fork of the Live Server NPM package, which I then also published to the vscode multiplier. Then we have html2app.dev, which is a free service for now, which converts your html apps to native apps using capacitive. At the moment, it uses capacitive version 4. I haven't had time to update to the latest version. Then now, as I said before, I'm teaching WebDev, mostly Javascript, HTML, CSS, SQL. Then I do still maintain some commercial products. And because of all of that I don't have much time to work on open source. I do try to keep them up to date, maintain them, but it's not that easy if you don't have much time. The only library that I use right now a lot is Nano.jsx, but it is pretty stable, so I don't have to make a lot of updates unless there are new features I want to add. I guess I will quickly show you those things. Let's see. Here is Enable2D. It looks like that. We just have three.js and some physics. Then Nano.jsx, a simple JSX library. It's isomorphic, so you can use it on the server and the client and mix it. Then here is HTML2 app, which converts your HTML5 objects to capacity-based mobile apps. Here FiveServe.

2. Introduction to Geckos.io and UDP#

Short description:

It's like a better live server with more features and kind of an improvement over the old one. Some of my bigger projects. Geckos.io is a real-time client-server communication over UDP using WebRTC and node.js. UDP is used in real-time multiplayer games for its speed and reliability. I built Geckos to enable UDP connections between browsers and Node.js servers using WebRTC. The initial version used the WRTC library, but later I found the Node data channel library to be much better.

It's like a better live server with more features and kind of an improvement over the old one. I guess that's it. Some of my bigger projects.

Then let's go to geckos.io, which I will go into a detail here. Very detailed here. Let's go to its website. We have that. Let's go to its website. It says it's a real time client server communication over UDP using WebRTC and node.js. What does that mean? First we have to know what is UDP, what is TCP. I will not go into very detailed things here. You can just like say. So most real time or kind of all real time multiplayer games you install on your desktop or your Playstation, your console use UDP for real time connections because it's unreliable and unordered or you can set it, that you want it unreliable and unordered and that makes it perfect for multiplayer games. The theory about that you can read it yourself I guess you already know it since you are watching this video and I kind of skipped why I did it. Well I was doing multiplayer games, I was reading a lot and figured out that UDP was much faster but UDP wasn't available in the browser, at least not for client server connections. If you know WebRTC, there you can use UDP for peer-to-peer, so client-to-client connections, but client-to-server connections was something that the browser couldn't do or there wasn't really a thing or some people did it with other libraries. But in Node.js, at least as far as I know, it wasn't possible, so I tried to build it. So, I built Geckos. Let's go to the repository. Here you have the repository.

The version 1 of Geckos was built on the library WRTC, which is like a huge binary. It was slow. Connections were slow. And it wasn't useful, but it did work. So, you could make a browser to Node.js server UDP connections using WebRTC. So, the server itself would handle the signaling between itself and the client. Then you had to make server IP public, so the client could directly connect to the server via WebRTC data channels. And then later I've found that the Node data channel library was much better. And it was designed. This here is the repo.

3. Geckos.io and UDP#

Short description:

It's nodejs-bindings for libdata-channel. It uses WebRTC connections from the browser to the server. The server IP has to be public for the client to connect directly. You have to open UDP ports on the server and handle signaling through an HTTP request. Users often get stuck at deployment. Here is a video comparing UDP and TCP.

It's nodejs-bindings for libdata-channel. And it was built by Murat. And the libdata-channel itself is written in C, C++. And it's very lightweight and is developed by Paul-Louis Agneau. Okay. And still a lot of commits every week. And it works pretty fast, and it's pretty lightweight. And, yeah, it's pretty... Never had issues so far with it. So thank you both for developing it.

Okay, now. So where was I? How does it work? Okay, so as I said, it uses WebRTC connections, WebRTC data channel connections from the browser to the server and the signaling is also done on the server and the server IP has to be public for the client directly to connect to that server. Most people, I guess, struggle if they have a load balancer in front. Let's assume you have an NGINX server here and then here is like Docker server or Docker swarm and the WebRTC connections do not go through the NGINX servers, through the load balancer. Only the data, HTTP and so on goes to the load balancer but the client has to connect directly to the server itself. So that's why you have to open these UDPs ports on the server itself but all the signaling goes through a HTTP request. A lot of people who use Kekos kind of get stuck there. And also since it uses UDP, I mean, you can use TCP if you want but that's kind of nonsense because you have better things that use TCP, like WebSockets. You have to have the kind of knowledge about how to set up a server, how to install these things, how to forward these ports. You can't just host gatecost.io app on services like Heroku. And I see a lot of users who use Geckos, they get stuck at the deployment. Therefore I go quickly over those steps. Let's see. Change log times to dock. Let's see. Yeah, there is no problem where was it? OK, first, here is a very nice video that compares UDP and TCP. Here you will see it demonstrates package loss. With normal landline Internet connections you would not really experience package loss, but if you have an Internet connection that is very bad, or maybe you have something, a satellite Internet connection with a lot of package loss and huge latency, there you would see things like in this video. Just have a look if you are interested. And another video quickly.

4. Geckos.io, Deployment, and Docker#

Short description:

This video provides a good overview of how WebRTC works, including signaling, STUN, and turn services. For Geckos deployment, you need to open UDP ports, with the default signaling port being 9208. Geckos is ideal for real-time multiplayer games, but for turn-based games like chess, socket.io or simple HTTP requests are sufficient. I will now demonstrate how Geckos works with Docker, using a simple example with an express server and Geckos initialization.

This one is also very useful video, if you have not enough knowledge about WebRTC. I quickly open it here. It's a very good talk about how all works, how the signaling works, and about STUN and turn service and so on. I encourage you to watch this video here.

I want to go through the ports you have to open. Let's see. Ah, here, deployment. So, for the deployment you have to open these UDP ports, because it uses one of these ports. And by default, it uses 9208 for the signaling, but you can define that in your application. You will find that in the documentation. But since here you have to open UDP port and services like Heroku or other services that include all-in-one service for node deployments, you can't use it.

Then, quickly here, when you should use or should not use the deployment Geckos, Geckos really shines when you have real-time multiplayer games with an authoritative server. A real-time shooter, for example. If you just want to make a chess game, round turn-based chess game, there is no need for Geckos. You can simply use socket.io or even simple HTTP requests. Okay, I guess that's it.

Now I will go and show you how it works with Docker. I have built an example. If you start with Geckos, you should first read this example. It's very simple. You have a server.js file. It uses express server. Then here is some Geckos initialization and very simple code. And I have also published that app as a docker file on docker container and I will just show you how it works. Let's see. I will connect to a server. I have installed Ubuntu and docker. You can see that it's running on EC2 instance and it should work out of the box. Let's see. If I install that, you can see the, I open, I forward port 3000 TCP where the server and signaling is done in case of this app here and I forward UDP port range between 10,000 and 10,007 because I limited in this application I have limited the port range between these two and it then uses multiplex so you can use multiple UDP connections on the same port.

5. Connecting via WebRTC and Hosting Multiple Servers#

Short description:

We are now connected on port 3000 via WebRTC, allowing communication between clients through the server. This example demonstrates the use of multiple KCOS servers on the same server with different port ranges. By forwarding the app to port 3001 and setting the min and max UDP ports to 1001, multiple containers can be hosted on the same server.

Okay that is running. Now I just have to grab the IP. Okay and let's see on port 3000 we are now connected so you can write anything, open new window and then talk to each other just like a simple chat app. And this is now all done via WebRTC and it goes from one client to the server and then to the other client. And what's so neat about this example here uh where is this client yeah is that it shows you how you can use multiple different uh stock KCOS server on the same server with different port ranges. So here I forward the app to 3001 and I open just one port and set that to min and max UDP port to 1001 and so you can host multiple of these containers on the same server. Yes.

Yannick
Yannick
21 min
28 Sep, 2023

Comments

Sign in or register to post your comment.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Optimizing HTML5 Games: 10 Years of Learnings
JS GameDev Summit 2022JS GameDev Summit 2022
33 min
Optimizing HTML5 Games: 10 Years of Learnings
Top Content
Watch video: Optimizing HTML5 Games: 10 Years of Learnings
PlayCanvas is an open-source game engine used by game developers worldwide. Optimization is crucial for HTML5 games, focusing on load times and frame rate. Texture and mesh optimization can significantly reduce download sizes. GLTF and GLB formats offer smaller file sizes and faster parsing times. Compressing game resources and using efficient file formats can improve load times. Framerate optimization and resolution scaling are important for better performance. Managing draw calls and using batching techniques can optimize performance. Browser DevTools, such as Chrome and Firefox, are useful for debugging and profiling. Detecting device performance and optimizing based on specific devices can improve game performance. Apple is making progress with WebGPU implementation. HTML5 games can be shipped to the App Store using Cordova.
Remix Flat Routes – An Evolution in Routing
Remix Conf Europe 2022Remix Conf Europe 2022
16 min
Remix Flat Routes – An Evolution in Routing
Top Content
Remix Flat Routes is a new convention that aims to make it easier to see and organize the routes in your app. It allows for the co-location of support files with routes, decreases refactor and redesign friction, and helps apps migrate to Remix. Flat Folders convention supports co-location and allows importing assets as relative imports. To migrate existing apps to Flat Routes, use the Remix Flat Routes package's migration tool.
Building Fun Experiments with WebXR & Babylon.js
JS GameDev Summit 2022JS GameDev Summit 2022
33 min
Building Fun Experiments with WebXR & Babylon.js
Top Content
This Talk explores the use of Babylon.js and WebXR to create immersive VR and AR experiences on the web. It showcases various demos, including transforming a 2D game into a 3D and VR experience, VR music composition, AR demos, and exploring a virtual museum. The speaker emphasizes the potential of web development in the metaverse and mentions the use of WebXR in Microsoft products. The limitations of WebXR on Safari iOS are discussed, along with the simplicity and features of Babylon.js. Contact information is provided for further inquiries.
Making Awesome Games with LittleJS
JS GameDev Summit 2022JS GameDev Summit 2022
34 min
Making Awesome Games with LittleJS
Top Content
Little.js is a super lightweight and fast JavaScript game engine that has everything included to start making games right away. It has a tiny footprint and no dependencies, making it perfect for size-coding competitions like JS13K. Little.js is built with an object-oriented structure and comes with several classes. It provides a fast rendering system, a comprehensive audio system, and various starter projects for different game types. Little.js is designed to be simple and easy to understand, allowing you to look at and modify the code.
Boost the Performance of Your WebGL Unity Games!
JS GameDev Summit 2023JS GameDev Summit 2023
7 min
Boost the Performance of Your WebGL Unity Games!
The Talk discusses ways to boost the performance of WebGL Unity games, including issues with bundle size, memory usage, and runtime performance. It suggests using Brotli for compression and non-exception support for better performance. Choosing the appropriate texture compression format and experimenting with separate builds can also help. The Talk also covers optimizing textures, models, audio, and assets by reducing build size, using compression, disabling unnecessary models, and optimizing audio quality. Unity's optimization tools and profilers are recommended for analyzing performance and memory issues.
How Not to Build a Video Game
React Summit 2023React Summit 2023
32 min
How Not to Build a Video Game
Watch video: How Not to Build a Video Game
The Talk showcases the development of a video game called Athena Crisis using web technologies like JavaScript, React, and CSS. The game is built from scratch and includes features like multiple game states, AI opponents, and map editing. It demonstrates the benefits of using CSS for game development, such as instant load times and smooth transitions. The Talk also discusses optimizing performance, supporting dark mode, and publishing the game to other platforms.

Workshops on related topic

Make a Game With PlayCanvas in 2 Hours
JSNation 2023JSNation 2023
116 min
Make a Game With PlayCanvas in 2 Hours
Top Content
Featured WorkshopFree
Steven Yau
Steven Yau
In this workshop, we’ll build a game using the PlayCanvas WebGL engine from start to finish. From development to publishing, we’ll cover the most crucial features such as scripting, UI creation and much more.
Table of the content:- Introduction- Intro to PlayCanvas- What we will be building- Adding a character model and animation- Making the character move with scripts- 'Fake' running- Adding obstacles- Detecting collisions- Adding a score counter- Game over and restarting- Wrap up!- Questions
Workshop levelFamiliarity with game engines and game development aspects is recommended, but not required.
Integrating LangChain with JavaScript for Web Developers
React Summit 2024React Summit 2024
92 min
Integrating LangChain with JavaScript for Web Developers
Featured Workshop
Vivek Nayyar
Vivek Nayyar
Dive into the world of AI with our interactive workshop designed specifically for web developers. "Hands-On AI: Integrating LangChain with JavaScript for Web Developers" offers a unique opportunity to bridge the gap between AI and web development. Despite the prominence of Python in AI development, the vast potential of JavaScript remains largely untapped. This workshop aims to change that.Throughout this hands-on session, participants will learn how to leverage LangChain—a tool designed to make large language models more accessible and useful—to build dynamic AI agents directly within JavaScript environments. This approach opens up new possibilities for enhancing web applications with intelligent features, from automated customer support to content generation and beyond.We'll start with the basics of LangChain and AI models, ensuring a solid foundation even for those new to AI. From there, we'll dive into practical exercises that demonstrate how to integrate these technologies into real-world JavaScript projects. Participants will work through examples, facing and overcoming the challenges of making AI work seamlessly on the web.This workshop is more than just a learning experience; it's a chance to be at the forefront of an emerging field. By the end, attendees will not only have gained valuable skills but also created AI-enhanced features they can take back to their projects or workplaces.Whether you're a seasoned web developer curious about AI or looking to expand your skillset into new and exciting areas, "Hands-On AI: Integrating LangChain with JavaScript for Web Developers" is your gateway to the future of web development. Join us to unlock the potential of AI in your web projects, making them smarter, more interactive, and more engaging for users.
PlayCanvas End-to-End : the quick version
JS GameDev Summit 2022JS GameDev Summit 2022
121 min
PlayCanvas End-to-End : the quick version
Top Content
WorkshopFree
João Ruschel
João Ruschel
In this workshop, we’ll build a complete game using the PlayCanvas engine while learning the best practices for project management. From development to publishing, we’ll cover the most crucial features such as asset management, scripting, audio, debugging, and much more.
Introduction to WebXR with Babylon.js
JS GameDev Summit 2022JS GameDev Summit 2022
86 min
Introduction to WebXR with Babylon.js
Workshop
Gustavo Cordido
Gustavo Cordido
In this workshop, we'll introduce you to the core concepts of building Mixed Reality experiences with WebXR and Balon.js.
You'll learn the following:- How to add 3D mesh objects and buttons to a scene- How to use procedural textures- How to add actions to objects- How to take advantage of the default Cross Reality (XR) experience- How to add physics to a scene
For the first project in this workshop, you'll create an interactive Mixed Reality experience that'll display basketball player stats to fans and coaches. For the second project in this workshop, you'll create a voice activated WebXR app using Balon.js and Azure Speech-to-Text. You'll then deploy the web app using Static Website Hosting provided Azure Blob Storage.
Tiny Game Live Coding Workshop
JS GameDev Summit 2023JS GameDev Summit 2023
115 min
Tiny Game Live Coding Workshop
Workshop
Frank Force
Frank Force
Dive into the captivating world of micro-game development with Frank Force in this interactive live coding workshop. Tailored for both seasoned developers and curious newcomers, this session explores the unique challenges and joys of creating games and demos with extreme size constraints.
Managers Are From Mars, Devs Are From Venus
TechLead Conference 2024TechLead Conference 2024
111 min
Managers Are From Mars, Devs Are From Venus
Workshop
Mo Khazali
Mo Khazali
A Developer’s Guide to Communicating, Convincing, and Collaborating Effectively With Stakeholders
It’s a tale as old as time - collaboration between developers and business stakeholders has long been a challenge, with a lack of clear communication often leaving both sides frustrated. The best developers can deeply understand their business counterparts’ needs, effectively communicate technical strategy without losing the non-technical crowd, and convince the business to make the right decisions. Working at a consultancy, I’ve both failed and succeeded in architecting and “selling” technical visions, learning many lessons along the way.Whether you work at a product company, are a consultant/freelancer, or want to venture beyond just being a developer, the ability to convince and clearly communicate with stakeholders can set you apart in the tech industry. This becomes even more important with the rise of GenAI and the increasingly competitive developer market, as problem-solving and effective communication are key to positioning yourself.In this workshop, I’ll share real-world examples, both good and bad, and guide you through putting the theory into practice through dojos.