#wasm #webrtc


UDP-like (unreliable, unordered) communication between Javascript/WebAssembly and native Rust via WebRTC

12 releases

0.5.3 Sep 17, 2022
0.5.2 Mar 14, 2022
0.5.1 May 3, 2021
0.5.0 Oct 24, 2020
0.2.1 Jun 2, 2019

#1130 in Network programming

Download history 100/week @ 2023-05-29 46/week @ 2023-06-05 62/week @ 2023-06-12 125/week @ 2023-06-19 93/week @ 2023-06-26 213/week @ 2023-07-03 179/week @ 2023-07-10 148/week @ 2023-07-17 78/week @ 2023-07-24 45/week @ 2023-07-31 87/week @ 2023-08-07 125/week @ 2023-08-14 137/week @ 2023-08-21 107/week @ 2023-08-28 168/week @ 2023-09-04 70/week @ 2023-09-11

505 downloads per month
Used in 6 crates (via naia-server-socket)

MIT license



Build Status Latest Version API Documentation

This is a Rust library which allows you to write a game server with browser based clients and UDP-like networking.

This crate is not meant as a general purpose WebRTC data channel system, it is instead designed to be used as the bottom level UDP-like transport layer of a higher level protocol in an environment where UDP is not available. It provides an async API for accepting WebRTC connections from browsers and sending and receiving WebRTC unreliable data channel messages from multiple clients.

The full set of protocols needed to implement WebRTC is daunting. This crate implements only the bare minimum subset of WebRTC required to support unreliable, unordered data channel messages. Because the WebRTC support is so minimal, this crate does not need to depend on a pre-existing heavyweight WebRTC implementation, but as such the protocol support is extremely limited.

You should expect only WebRTC data channels to function, and only in unreliable, unordered mode. Additionally, there is a stricter limit on WebRTC message lengths than what would be supported in a full WebRTC implementation. Only unfragmented SCTP packets are handled, so any message large enough to cause an SCTP packet to need fragmentation causes an error on write and is simply dropped on read. The maximum message length depends on the particular browser you connect with, but in my testing currently it is slightly smaller than 1200 bytes.

This crate is (mostly) async runtime agnostic, it is usable from a rust program using tokio, async-std, smol, some other runtime, or no runtime at all. This crate does not spawn background async tasks at all so it truly does not rely on an executor, but it does require an async reactor to deliver wake events for its UDP socket and timers. It uses async-io for this purpose, which is (arguably) minimal and async runtime agnostic. However, if async-io is not already in use by the rust program using this crate, it will automatically create a new background reactor thread internally. It would be better some day for webrtc-unreliable to be truly runtime agnostic, and not (indirectly) spawn a global background reactor thread, but this is currently waiting on a better async trait story. If this situation is problematic for you, please file an issue and I can move faster towards being truly runtime agnostic.

Running the example

In a terminal:

$ cargo run --example echo_server -- --data --http --public

Then, using a web browser, go to ''. Open the debug console, if everything is working correctly you should see messages being sent and received.

Please note that if you are using Firefox, Firefox does not accept WebRTC connections to, so you may need to use a different IP address.


This was originally a Rust / Tokio port of the WebUDP project, so the credit for the original design goes there.


This project is licensed under the MIT license


~232K SLoC