Renet2
Fork of renet
Renet2 is a network library for Server/Client games written in rust. It is focused on fast-paced games such as FPS, and competitive games.
Provides the following features:
- Client/Server connection management
- Message based communication using channels, they can have different guarantees:
- ReliableOrdered: guarantee of message delivery and order
- ReliableUnordered: guarantee of message delivery but not order
- Unreliable: no guarantee of message delivery or order
- Packet fragmention and reassembly
- Authentication and encryption, using renetcode2
- The transport layer can be customizable. The default transport can be disabled and replaced with a custom one.
- The underlying data transport/socket can be customized. Both unencrypted (e.g. UDP) and encrypted (e.g. WebTransport) data transports are supported.
- Built-in UDP sockets, in-memory sockets, WebTransport sockets, and WebSocket sockets for flexible, cross-platform networking using the
netcodeprotocol.
Differences from renet
netcode protocol changes
Renet2 extends the original netcode protocol with:
- Optional packet encryption. This supports data transports that do their own encryption.
- Optional transport reliability. This supports data transports that are automatically reliable.
- Servers with multiple concurrent data transports (e.g. UDP sockets and WebTransport).
See renetcode2/NETCODE_EXTENSIONS.md.
Features
- Includes built-in data transports: UDP, memory channels, WebTransport, WebSockets.
- See
src/examplesfor a fully cross-platform demo.
- See
Building docs
Build workspace docs (no WASM):
cargo doc --open --no-deps --all-features
Build WASM docs (renet2_netcode workspace crate only):
cd renet2_netcode &&\
cargo doc --open --no-deps --no-default-features --features=wt_client_transport,ws_client_transport --target wasm32-unknown-unknown
Channels
Renet communication is message based, and channels describe how the messages should be delivered.
Channels are unidirectional, ConnectionConfig.client_channels_config describes the channels that the clients sends to the server, and ConnectionConfig.server_channels_config describes the channels that the server sends to the clients.
Each channel has its own configuration ChannelConfig:
// No guarantee of message delivery or order
let send_type = Unreliable;
// Guarantee of message delivery and order
let send_type = ReliableOrdered ;
// Guarantee of message delivery but not order
let send_type = ReliableUnordered ;
let channel_config = ChannelConfig ;
Usage
Renet aims to have a simple API that is easy to integrate with any code base. Poll for new messages at the start of a frame with update. Call send_packets from the transport layer to send packets to the client/server.
Server
let mut server = new;
// Setup transport layer
const SERVER_ADDR: SocketAddr = new;
let socket: UdpSocket = bind.unwrap;
let server_config = ServerConfig ;
let mut transport = new.unwrap;
// Your gameplay loop
loop
Client
let mut client = new;
// Setup transport layer
const server_addr: SocketAddr = "127.0.0.1:5000".parse.unwrap;
let socket = bind.unwrap;
let current_time = now.duration_since.unwrap;
let authentication = Unsecure ;
let mut transport = new.unwrap;
// Your gameplay loop
loop
Demos
You can checkout the echo examples for a simple usage of the library. Usage:
- Server:
cargo run --example echo -- server 5000 - Client:
cargo run --example echo -- client 127.0.0.1:5000 CoolNickName
Or you can look into the two demos that have more complex uses of renet:
Plugins
Check out bevy_renet2 if you want to use renet2 as a plugin with the Bevy engine.
Check out bevy_replicon_renet2 if you want to use renet2 as a backend for bevy_replicon.
Check out renet2_steam if you want to use the steam transport layer instead of the default one.
Visualizer
Check out renet2_visualizer for an egui plugin to plot metrics data from renet clients and servers: