#web-rtc #udp-networking #gamedev #udp #udp-socket #sockets

naia-client-socket

Abstraction to expose common API over a UDP socket on Linux, and a unreliable WebRTC datachannel on the browser

34 releases (17 breaking)

0.24.1 Dec 27, 2024
0.23.0 Sep 17, 2024
0.22.0 Jan 10, 2024
0.20.1 Apr 1, 2023
0.3.0 Jul 13, 2020

#1114 in Network programming

Download history 35/week @ 2024-12-04 231/week @ 2024-12-11 20/week @ 2024-12-18 145/week @ 2024-12-25 3/week @ 2025-01-01 5/week @ 2025-01-08 30/week @ 2025-01-15 9/week @ 2025-01-22 13/week @ 2025-01-29 20/week @ 2025-02-05 282/week @ 2025-02-12 1/week @ 2025-02-19 27/week @ 2025-02-26 5/week @ 2025-03-05 34/week @ 2025-03-12 8/week @ 2025-03-19

74 downloads per month
Used in 5 crates (2 directly)

MIT/Apache

99KB
2K SLoC

Latest Version API Documentation Discord chat MIT/Apache

naia

a networking architecture for interactive applications

A cross-platform (including Wasm!) networking engine that intends to make multiplayer game development in Rust dead simple and lightning fast.

naia helps you to easily define a common, shared Protocol that allows Server & Client to exchange information. Then, naia facilitates sending/receiving parts of that Protocol as reliable/unreliable Messages between Server & Client, and also keeps a pool of tracked Entities synced with each Client for whom they are "in-scope". Entities are "scoped" to Clients with whom they share the same Room, as well as being sufficiently customizable to, for example, only keep Entities persisted & synced while within a Client's viewport or according to some other criteria.

The API is heavily inspired by the Nengi.js & Colyseus Javascript multiplayer networking libraries. The internals follow the Tribes 2 Networking model fairly closely.

Thank very much to Kyren for support & webrtc-unreliable, and to the Laminar authors, for the cannibalized code within.

Any help is very welcome, please get in touch! I am open to any criticism / feedback in order to better this project.

Currently guaranteed to work on Web & Linux, although Windows & MacOS have been reported working as well. Please file issues if you find inconsistencies and I'll do what I can.

For more detailed information, please look at the FAQ.

Demos

More comprehensive documentation / tutorials are on their way, but for now, the best way to get started with naia is to go through the basic demo, which demonstrates most of the functionality.

Server:

To run the basic server demo on Linux:

1. cd /naia/demos/basic/server
2. cargo run

To run the basic server demo on Linux:

1. // go to (https://docs.rs/openssl/latest/openssl/) to install openssl on your machine
2. cd /naia/demos/basic/server
3. cargo run

Client:

To run the basic client demo on Linux:

1. cd /naia/demos/basic/client/wasm_bindgen
2. cargo run

To run the basic client demo on Web:

1. cargo install cargo-web  // should only need to do this once if you haven't already
2. cargo install cargo-make // should only need to do this once if you haven't already
3. cd /naia/demos/basic/client/wasm_bindgen
4. make serve
5. Web page will be blank - check debug console to see communications from the server

Known Issues

To run a miniquad client you will require the following be installed

sudo apt-get install libxi-dev libgl1-mesa-dev

lib.rs:

Naia Client Socket

A Socket abstraction over either a UDP socket on native Linux, or a unreliable WebRTC datachannel on the browser

Dependencies

~2–20MB
~312K SLoC