Crates.io | matchbox_protocol |
lib.rs | matchbox_protocol |
version | 0.10.0 |
source | src |
created_at | 2023-03-31 12:31:39.717859 |
updated_at | 2024-07-15 06:30:00.186459 |
description | Common interfaces between matchbox_socket and matchbox_server |
homepage | https://github.com/johanhelsing/matchbox |
repository | https://github.com/johanhelsing/matchbox |
max_upload_size | |
id | 826298 |
size | 10,136 |
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:
ggrs
: A feature providing a ggrs compatible socket.matchbox_socket
integration for the Bevy game engine
bevy | bevy_matchbox |
---|---|
0.14 | 0.10, main |
0.13 | 0.9 |
0.12 | 0.8 |
0.11 | 0.7 |
0.10 | 0.6 |
< 0.9 | Unsupported |
bevy
and bevy_ggrs
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:
.await
the message loop future that processes new messages.
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.
Projects using Matchbox:
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.
matchbox_socket
is heavily inspired its wasm-bindgen server_socket and Matchbox would probably not exist without it.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.