Search Unity

Unity-Netcode.IO - Secure UDP Communication in WebGL

Discussion in 'Multiplayer' started by PhobicGunner, Aug 6, 2017.

  1. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    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.
     
  2. fhernand

    fhernand

    Joined:
    Mar 17, 2016
    Posts:
    4
    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.
     
  3. IAMBATMAN

    IAMBATMAN

    Joined:
    Aug 14, 2015
    Posts:
    272
    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...
     
  4. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    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).
     
    TakuanDaikon and PrimalCoder like this.
  5. tab-key

    tab-key

    Joined:
    Jul 3, 2017
    Posts:
    1
    Could you use Netcode on your unity client side to connect to a dedicated Photon server?
     
  6. adammpolak

    adammpolak

    Joined:
    Sep 9, 2018
    Posts:
    450
    @PhobicGunner sorry to be so late to the game, does this still exist and play nice with Unity's new netcode?
     
  7. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    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?