netcode.io
a brief refresher on different network protocols and why UDP isn't normally used in browsers until I eventually talk about
for a few minutes near the end
Protocols
- Mainly concerned with two layers of the full network stack:
- application
- e.g. HTTP, FTP
- transport
- e.g. TCP, UDP
- application


Protocols
- We're all (likely) familiar with HTTP and FTP!
- HTTP and FTP use TCP for their transport layer
- TCP has certain characteristics that fit the use-case:
- connection-based
- reliable packet delivery
- in-order packet delivery
- When requesting data or a file, you typically want all of its data in order
- as opposed to, say, a jigsaw puzzle of 500 packets that when correctly assembled form the .zip file or HTML page you actually want
Protocols
- UDP is the transport protocol that implements the bare minimum for sending outgoing data of any kind
- if you want any other characteristics, those need to be implemented on the application layer
- Games that update in real-time (MMOs, FPSes, etc.) typically use UDP for this reason, with some custom application layer that's game-specific
- It is possible to use TCP for real-time games, but this only works in the very best-case scenarios
- These games don't need every packet, only the most recent ones to describe current game state
- This is known as head-of-line blocking
Protocols
Hello, would you like to hear a TCP joke?
Yes, I’d like to hear a TCP joke.
OK, I will tell you a TCP joke.
OK, I will hear a TCP joke.
Are you ready to hear a TCP joke?
Yes, I am ready to hear a TCP joke.
OK, I am about to send the TCP joke. It will last 10 seconds, it has two characters, it does not have an explicit setting, it ends with a punchline.
OK, I am ready to get your TCP joke that will last 10 seconds, has two characters, does not have an explicit setting, and ends with a punchline.
I’m sorry, your connection has timed out… Hello, would you like to hear a TCP joke?
Protocols
I'd tell you a UDP joke, but you probably wouldn't get it.
Protocols in Browsers
- My recent DevTricks talks and hackathon project have been about writing or porting games from native desktop applications to be run in a browser
- i.e. emscripten
- So, of course, I had to think about what kind of network communication browsers allow right now
Protocols in Browsers
- Problem: Most games of the kind I want to make use UDP. Most browsers do not have easy means to use UDP.
- Javascript typically uses WebSockets, which is built on top of TCP
- QUIC uses UDP, but its implementation enforces in-order packet delivery, thus head-of-line blocking
- WebRTC allows for peer-based connections
- ... which might work, but overly complex for games with dedicated servers (requires ICE, STUN, TURN)
Protocols in Browsers
- Even bigger problem: Allowing for UDP as-is in a browser is a very, VERY bad idea, and there are good reasons why this isn't a thing
- Imagine a site that serves javascript that sends UDP packets to some DDoS target
- Imagine a site that serves js that makes a user's browser send UDP packets to try and get information about a corporate network and relays that info over https
- No encryption or authentication -- those are assumed to be implemented at application layer
netcode.io
- A current attempt at an application layer protocol that allows for the desired functionality of UDP that covers the problems inherent to UDP in browsers
-
Characteristics:
- Connection-based
- Encrypted
- Authenticated
-
There is a reference implementation here:
https://github.com/networkprotocol/netcode.io
netcode.io
- Three portions:
- Web backend (REST API)
- to form authenticated connections between server and client
- Dedicated server(s)
- where the actual state of the game lives
- Clients
- people actually playing the game
- not necessarily browsers, but potentially includes them by design
- Web backend (REST API)
netcode.io
- Current state:
- Reference implementations exist
- Ports to C#, GoLang, Rust exist
- Ports to Unity and Unreal Engine 4 exist
- Use in a browser still requires users to install a browser plugin
- Not sure where the future of this is, honestly
- Is plugin installation going to affect user adoption?
- Are browsers going to implement this natively at some point?
but it's neat and I like exploring what's possible and why things are the way they are
Sources:
- http://www.firewall.cx/
- https://gafferongames.com/post/why_cant_i_send_udp_packets_from_a_browser/
- https://github.com/networkprotocol/netcode.io
- https://github.com/networkprotocol/netcode.io/blob/master/STANDARD.md
- https://github.com/RedpointGames/netcode.io-browser
netcode.io
By tdhoward
netcode.io
- 908