Making a game with Pion

Cross platform multiplayer without proprietary APIs is possible thanks to Pion!

Srayan Jana -- 2025-09-09


(The following was adapted from a talk I gave at DWeb Weekend 2025 at the Internet Archive in San Francisco on August 17, 2025)

Simplifying WebRTC Datachannels for Games

First of all, to get some stuff out of the way, instead of using the “super complicated” WebRTC datachannels, why don’t we use something simpler?

Why Not Use Websockets?

  • Too slow: Most games use UDP with a reliability layer on top.
  • Suitable for turn-based games: Fine for games that are turn-based/slow-paced, like Runescape.
  • For more details, see:

The Case for Web Transport

  • Replacement for Websockets, uses QUIC instead of TCP.
  • However, it has been in development for a long time, and I want to get started on making games now.
  • Current issues:
  • Potential: Will probably solve most problems once finished and would be the best choice for making a multiplayer game on the web.

Datachannels: A Hidden Gem of WebRTC

Benefits and Drawbacks of WebRTC

Benefits

  • Host flexibility: Do not need to host servers - players can make their own.
    • No more need for port forwarding or Hamachi!
  • Minimal server requirements: Only need one server for signaling.
  • Community-supported specification: There are many options for making your own WebRTC-based app.

Drawbacks

  • Complex setup: Setting up WebRTC is challenging.
  • Server dependence: You need to host or use two different servers (Signaling + STUN/TURN).
    • Can use Google’s STUN, but combining signaling and STUN into one server would be nice.

WebRTC Implementations

  • libwebrtc - (a fork of) the original WebRTC implementation.
  • libdatachannel - C/C++.
  • Pion WebRTC - Go.
  • webrtc-rs - Rust (using Tokio Runtime).
  • str0m - Rust (sans-io).
  • sipsorcery - C#
  • GameNetworkingSockets
    • Uses ICE and STUN/TURN for Peer to Peer.
    • Created by Valve and made for Steam, which means if you’ve ever played a game like Counter Strike or Deadlock, you’ve already seen this library in action!

Existing Game Networking Libraries Using WebRTC

  • Geckos.io
    • A client-server abstraction for WebRTC Datachannels written in Node.js.
    • Past experience: Really nice but a bit inefficient. See GitHub Issue.
  • Netlib - Peer-to-peer WebRTC datachannel library for TypeScript.
  • Matchbox - WebRTC datachannel library for Rust, compiles to both native and WASM.
  • PeerJS - Great for browser-only apps/games, not specifically for game networking.
  • Netplayjs - Untested but seems to work well.
  • Godot Engine’s WebRTC Native - Official Godot bindings to libdatachannel for Godot’s multiplayer API.

Real-World Uses

Why Go for Development?

  • Efficient: It just gets the job done.
  • Pion: Has a pure-Go implementation of WebRTC.
  • Minimal dependencies: No need for external dependencies like OpenSSL.

Why Not Rust?

  • Preference: I like Rust, but Go has a more active scene/easier help for WebRTC.
  • Speed of development: It’s faster to code in Go compared to Rust.

Why Ebitengine for Game Development?

Official Pion Example

  • We now have an official example using Ebitengine in the Pion example-webrtc-applications repository
  • This includes an bundled in signaling server so you can host your own lobby, and connect with another player.
  • Github Link to Game
  • PR where it was merged in: Example WebRTC Applications
  • Limitations
    • Right now, this can only support two players on the same computer
      • Could probably work between two different computers, but we would need to figure out how to setup CORS properly for the signaling server
      • The machinery is there to support more than two players in a lobby, but as of writing this article it is currently hardcoded to just two Picture of game

Other Games That Use WebRTC

Possibilities with WebRTC

  • Hosting a Minecraft-style game without dedicated servers or port forwarding.
  • Players host everything themselves: no need for VPN/Hamachi.

Community Acknowledgements