Renet
Renet 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 fragmentation and reassembly
- Authentication and encryption, using renet_netcode
- You can also use renet_steam to use the
Steamtransport and authenticantion layer - The transport/authentication layer can be customizable, you can write your own if necessary
- You can also use renet_steam to use the
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 using renet_netcode
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 using renet_netcode
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
Transport Layers
Checkout renet_netcode if you want to use UDP with the netcode protocol.
Checkout renet_steam if you want to use the steam transport layer.
Demos
You can checkout the echo example 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
Checkout bevy_renet if you want to use renet as a plugin with the Bevy engine.
Visualizer
Checkout renet_visualizer for a egui plugin to plot metrics data from renet clients and servers: