Renet

Latest version Documentation MIT Apache

Renet is a network library for Server/Client games written in rust. Built on top of UDP, it is focused on fast-paced games such as FPS, and competitive games that need authentication. Provides the following features:

Sections: * Usage * Demos * Plugins * Visualizer

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, messages sent during a frame - or that need to be resent - are aggregated and sent together with sent_packets.

Server

```rust let deltatime = Duration::frommillis(16); let mut server = RenetServer::new(...); let channel_id = 0;

// Your gameplay loop loop { // Receive new messages and update clients server.update(delta_time)?;

// Check for client connections/disconnections
while let Some(event) = server.get_event() {
    match event {
        ServerEvent::ClientConnected(id, user_data) => {
            println!("Client {} connected", id);
        }
        ServerEvent::ClientDisconnected(id) => {
            println!("Client {} disconnected", id);
        }
    }
}

// Receive message from channel
for client_id in server.clients_id().into_iter() {
    while let Some(message) = server.receive_message(client_id, channel_id) {
        // Handle received message
    }
}

// Send a text message for all clients
server.broadcast_message(channel_id, "server message".as_bytes().to_vec());

// Send message to only one client
let client_id = ...;
server.send_message(client_id, channel_id, "server message".as_bytes().to_vec());

// Send packets to clients
server.send_packets()?;

} ```

Client

```rust let deltatime = Duration::frommillis(16); let mut client = RenetClient::new(...); let channel_id = 0;

// Your gameplay loop loop { // Receive new messages and update client client.update(delta_time)?;

if client.is_connected() {
    // Receive message from server
    while let Some(message) = client.receive_message(channel_id) {
        // Handle received message
    }

    // Send message
    client.send_message(channel_id, "client text".as_bytes().to_vec());
}

// Send packets to server
client.send_packets()?;

} ```

Demos

You can checkout the echo example for a simple usage of the library. Or you can look into the two demos that have more complex uses of renet:

Bevy Demo
Simple bevy application to demonstrate how you could replicate entities and send reliable messages as commands from the server/client using renet:

Bevy Demo.webm

Repository

Chat Demo
Simple chat application made with egui to demonstrate how you could handle errors, states transitions and client self hosting:

Chat Demo.webm

Repository

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:

https://user-images.githubusercontent.com/35241085/175834010-b1eafd77-7ea2-47dc-a915-a399099c7a99.mp4