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 garantees:
- ReliableOrdered: garantee of message delivery and order
- ReliableUnordered: garantee of message delivery but not order
- Unreliable: no garantee of message delivery or order
- Packet fragmention and reassembly
- Authentication and encryption, using renetcode
- The transport layer can be customizable. The default transport can be disabled and replaced with a custom one
Channels
Renet communication is message based, and channels describe how the messages should be delivered.
Channels are unilateral, 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 garantee of message delivery or order
let send_type = Unreliable;
// Garantee 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. Pool 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 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: