Unity-Netcode.IO - Secure UDP Communication in WebGL

Hello!
If you haven’t been keeping up with this, Glenn Fiedler (a know industry expert, having worked on titles such as Titanfall 1+2) has created a proposal for a new protocol called Netcode.IO
Netcode.IO is a secure method of communicating over UDP sockets - secure enough for a browser to adopt as a standard alongside options like WebSockets (which is the primary target of the Netcode.IO proposal - browser adoption).
While it is not available built-in to browsers yet, a third party browser extension allows you to begin using it already (I’ve tested it in Chrome, the Firefox plugin is still pending approval and signing)

So I thought, why not build an API on top of this so that WebGL builds can take advantage of it? So I did that.
But I also decided to create an entire from-scratch implementation of the spec in pure C# (Netcode.IO.NET), and then modified my Unity API to use that.

So what you have is a highly cross-platform API that just seamlessly works between browsers and standalone builds, is a secure connection-based protocol which is extremely easy to use, and is as fast as the fastest games will need (no head of line blocking like you get with TCP and WebSockets).

I wanted to present this here, because it seems like an important step in the evolution of multiplayer on the web. Hopefully we can drive adoption of this model so that we can ditch WebSockets and the inherent lag (and complete unsuitability for some types of games) and have a UDP protocol at our disposal.

5 Likes

Hi PhobicGunner,
amazing work, thanks for sharing! Having the flexibility of using this both in WebGL and Standalone builds makes this a very valuable contribution. Hopefully netcode.io gets adopted as a standard soon.

Great work! Though “Unity-Netcode.IO makes use of Netcode.IO.NET to provide support on most platforms except for WebGL (handled via JS plugin).” Am I missing something, or does that mean it doesn’t work with webgl…

It DOES work with WebGL. I should clarify that a bit - what that means is that on WebGL, it uses a Javascript JSLIB plugin to provide functionality for using the client API. On all other platforms, it seamlessly switches over to using Netcode.IO.NET instead, and also provides a server API.
So it works on both (except for the server APIs, which are unavailable in WebGL).

2 Likes

Could you use Netcode on your unity client side to connect to a dedicated Photon server?

@PhobicGunner sorry to be so late to the game, does this still exist and play nice with Unity’s new netcode?

Interesting. Did you do any benchmarks to see how well it scales when running it inside Unity?

Unity still uses Mono sockets, which often give you unexpected results when compared to running it outside of Unity.

On Github you mentioned minimal GC, could you elaborate on that please?