johanhelsing/matchbox

Painless peer-to-peer WebRTC networking for rust wasm (and native!)

Rust

1,154

1,030 commits

updated Jun 2, 2026

See the code

README

Matchbox

crates.io MIT/Apache 2.0 crates.io docs.rs

Painless peer-to-peer WebRTC networking for rust's native and wasm applications.

The goal of the Matchbox project is to enable udp-like, unordered, unreliable p2p connections in web browsers or native to facilitate low-latency multiplayer games.

Matchbox supports both unreliable and reliable data channels, with configurable ordering guarantees and variable packet retransmits.

The Matchbox project contains:

  • matchbox_socket: A socket abstraction for Wasm or Native, with:

    • ggrs: A feature providing a ggrs compatible socket.
  • matchbox_signaling: A signaling server library, with ready to use examples

  • matchbox_server: A ready to use full-mesh signalling server

  • bevy_matchbox: A matchbox_socket integration for the Bevy game engine

    bevybevy_matchbox
    0.180.14, main
    0.170.13
    0.160.12
    0.150.11
    0.140.10
    0.130.9
    0.120.8
    0.110.7
    0.100.6
    < 0.9Unsupported

Examples

How it works

Connection

WebRTC allows direct connections between peers, but in order to establish those connections, some kind of signaling service is needed. matchbox_server is such a service. Once the connections are established, however, data will flow directly between peers, and no traffic will go through the signaling server.

The signaling service needs to run somewhere all clients can reach it over http or https connections. In production, this usually means the public internet.

When a client wants to join a p2p (mesh) network, it connects to the signaling service. The signaling server then notifies the peers that have already connected about the new peer (sends a NewPeer event).

Peers then negotiate a connection through the signaling server. The initiator sends an "offer" and the recipient responds with an "answer." Once peers have enough information relayed, a RTCPeerConnection is established for each peer, which comes with one or more data channels.

All of this, however, is hidden from rust application code. All you will need to do on the client side, is:

  • Create a new socket, and give it a signaling server url
  • .await the message loop future that processes new messages.
    • If you are using Bevy, this is done automatically by bevy_matchbox (see the bevy_ggrs example).
    • Otherwise, if you are using WASM, wasm-bindgen-futures can help (see the simple example).
    • Alternatively, the future can be polled manually, i.e. once per frame.

You can hook into the lifecycle of your socket through the socket's API, such as connection state changes. Similarly, you can send packets to peers using the socket through a simple, non-blocking method.

Showcase

Projects using Matchbox:

Contributing

PRs welcome!

If you have questions or suggestions, feel free to make an issue. There's also a Discord channel if you want to get in touch.

Thanks

  • A huge thanks to Ernest Wong for his Dango Tribute experiment! matchbox_socket is heavily inspired its wasm-bindgen server_socket and Matchbox would probably not exist without it.

License

All code in this repository dual-licensed under either:

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

full-mesh
mesh-networks
p2p
rust
signalling-server
wasm
wasm-bindgen
webrtc

johanhelsing/matchbox

Painless peer-to-peer WebRTC networking for rust wasm (and native!)

Rust

1,154

1,030 commits

updated Jun 2, 2026

See the code

README

Matchbox

crates.io MIT/Apache 2.0 crates.io docs.rs

Painless peer-to-peer WebRTC networking for rust's native and wasm applications.

The goal of the Matchbox project is to enable udp-like, unordered, unreliable p2p connections in web browsers or native to facilitate low-latency multiplayer games.

Matchbox supports both unreliable and reliable data channels, with configurable ordering guarantees and variable packet retransmits.

The Matchbox project contains:

  • matchbox_socket: A socket abstraction for Wasm or Native, with:

    • ggrs: A feature providing a ggrs compatible socket.
  • matchbox_signaling: A signaling server library, with ready to use examples

  • matchbox_server: A ready to use full-mesh signalling server

  • bevy_matchbox: A matchbox_socket integration for the Bevy game engine

    bevybevy_matchbox
    0.180.14, main
    0.170.13
    0.160.12
    0.150.11
    0.140.10
    0.130.9
    0.120.8
    0.110.7
    0.100.6
    < 0.9Unsupported

Examples

How it works

Connection

WebRTC allows direct connections between peers, but in order to establish those connections, some kind of signaling service is needed. matchbox_server is such a service. Once the connections are established, however, data will flow directly between peers, and no traffic will go through the signaling server.

The signaling service needs to run somewhere all clients can reach it over http or https connections. In production, this usually means the public internet.

When a client wants to join a p2p (mesh) network, it connects to the signaling service. The signaling server then notifies the peers that have already connected about the new peer (sends a NewPeer event).

Peers then negotiate a connection through the signaling server. The initiator sends an "offer" and the recipient responds with an "answer." Once peers have enough information relayed, a RTCPeerConnection is established for each peer, which comes with one or more data channels.

All of this, however, is hidden from rust application code. All you will need to do on the client side, is:

  • Create a new socket, and give it a signaling server url
  • .await the message loop future that processes new messages.
    • If you are using Bevy, this is done automatically by bevy_matchbox (see the bevy_ggrs example).
    • Otherwise, if you are using WASM, wasm-bindgen-futures can help (see the simple example).
    • Alternatively, the future can be polled manually, i.e. once per frame.

You can hook into the lifecycle of your socket through the socket's API, such as connection state changes. Similarly, you can send packets to peers using the socket through a simple, non-blocking method.

Showcase

Projects using Matchbox:

Contributing

PRs welcome!

If you have questions or suggestions, feel free to make an issue. There's also a Discord channel if you want to get in touch.

Thanks

  • A huge thanks to Ernest Wong for his Dango Tribute experiment! matchbox_socket is heavily inspired its wasm-bindgen server_socket and Matchbox would probably not exist without it.

License

All code in this repository dual-licensed under either:

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

full-mesh
mesh-networks
p2p
rust
signalling-server
wasm
wasm-bindgen
webrtc

Project health

crates.io

Latest release

0.0.1 · Sep 11, 2021

Releases this year

0

Significant stargazers

(top 24 of 32)

Jonas Platte

660 followers · starred Mar 2023

John Nunley

331 followers · starred Apr 2023

Sven-Hendrik Haase

1,088 followers · starred Feb 2022

Peter Kieltyka

831 followers · starred Dec 2022