{"id":13625932,"url":"https://github.com/lucaspoffo/renet","last_synced_at":"2025-04-16T10:33:52.260Z","repository":{"id":37831090,"uuid":"285869483","full_name":"lucaspoffo/renet","owner":"lucaspoffo","description":"Server/Client network library for multiplayer games with authentication and connection management made with Rust","archived":false,"fork":false,"pushed_at":"2024-08-19T18:35:46.000Z","size":945,"stargazers_count":676,"open_issues_count":17,"forks_count":66,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-11-06T11:52:24.015Z","etag":null,"topics":["gamedev","network","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lucaspoffo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"lucaspoffo"}},"created_at":"2020-08-07T16:04:02.000Z","updated_at":"2024-11-06T03:41:36.000Z","dependencies_parsed_at":"2023-11-07T04:49:28.696Z","dependency_job_id":"e7717545-1842-4c22-aec5-39bba745aeba","html_url":"https://github.com/lucaspoffo/renet","commit_stats":{"total_commits":396,"total_committers":8,"mean_commits":49.5,"dds":"0.16666666666666663","last_synced_commit":"96b664a6ebba5cb6a632171b989f5398286d9a63"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucaspoffo%2Frenet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucaspoffo%2Frenet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucaspoffo%2Frenet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucaspoffo%2Frenet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucaspoffo","download_url":"https://codeload.github.com/lucaspoffo/renet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223708455,"owners_count":17189781,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gamedev","network","rust"],"created_at":"2024-08-01T21:02:06.025Z","updated_at":"2025-04-16T10:33:52.241Z","avatar_url":"https://github.com/lucaspoffo.png","language":"Rust","funding_links":["https://github.com/sponsors/lucaspoffo"],"categories":["Rust","Networking"],"sub_categories":[],"readme":"# Renet\n\n[![Latest version](https://img.shields.io/crates/v/renet.svg)](https://crates.io/crates/renet)\n[![Documentation](https://docs.rs/renet/badge.svg)](https://docs.rs/renet)\n![MIT](https://img.shields.io/badge/license-MIT-blue.svg)\n![Apache](https://img.shields.io/badge/license-Apache-blue.svg)\n\nRenet is a network library for Server/Client games written in rust. It is focused on fast-paced games such as FPS, and competitive games.\nProvides the following features:\n\n- Client/Server connection management\n- Message based communication using channels, they can have different guarantees:\n    - ReliableOrdered: guarantee of message delivery and order\n    - ReliableUnordered: guarantee of message delivery but not order\n    - Unreliable: no guarantee of message delivery or order\n- Packet fragmentation and reassembly\n- Authentication and encryption, using [renet_netcode](https://github.com/lucaspoffo/renet/tree/master/renet_netcode)\n    - You can also use [renet_steam](https://github.com/lucaspoffo/renet/tree/master/renet_steam) to use the `Steam` transport and authenticantion layer\n    - The transport/authentication layer can be customizable, you can write your own if necessary\n\n## Channels\n\nRenet communication is message based, and channels describe how the messages should be delivered.\nChannels 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.\n\nEach channel has its own configuration `ChannelConfig`:\n\n```rust\n// No guarantee of message delivery or order\nlet send_type = SendType::Unreliable;\n// guarantee of message delivery and order\nlet send_type = SendType::ReliableOrdered {\n    // If a message is lost, it will be resent after this duration\n    resend_time: Duration::from_millis(300)\n};\n\n// Guarantee of message delivery but not order\nlet send_type = SendType::ReliableUnordered {\n    resend_time: Duration::from_millis(300)\n};\n\nlet channel_config = ChannelConfig {\n    // The id for the channel, must be unique within its own list,\n    // but it can be repeated between the server and client lists.\n    channel_id: 0,\n    // Maximum number of bytes that the channel may hold without acknowledgement of messages before becoming full.\n    max_memory_usage_bytes: 5 * 1024 * 1024, // 5 megabytes\n    send_type\n};\n```\n\n## Usage\n\nRenet 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.\n\n### Server\n\n```rust\nlet mut server = RenetServer::new(ConnectionConfig::default());\n\n// Setup transport layer using renet_netcode\nconst SERVER_ADDR: SocketAddr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 5000);\nlet socket: UdpSocket = UdpSocket::bind(SERVER_ADDR).unwrap();\nlet server_config = ServerConfig {\n    current_time: SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap(),\n    max_clients: 64,\n    protocol_id: 0,\n    public_addresses: vec![SERVER_ADDR],\n    authentication: ServerAuthentication::Unsecure\n};\nlet mut transport = NetcodeServerTransport::new(server_config, socket).unwrap();\n\n// Your gameplay loop\nloop {\n    let delta_time = Duration::from_millis(16);\n    // Receive new messages and update clients\n    server.update(delta_time);\n    transport.update(delta_time, \u0026mut server)?;\n    \n    // Check for client connections/disconnections\n    while let Some(event) = server.get_event() {\n        match event {\n            ServerEvent::ClientConnected { client_id } =\u003e {\n                println!(\"Client {client_id} connected\");\n            }\n            ServerEvent::ClientDisconnected { client_id, reason } =\u003e {\n                println!(\"Client {client_id} disconnected: {reason}\");\n            }\n        }\n    }\n\n    // Receive message from channel\n    for client_id in server.clients_id() {\n        // The enum DefaultChannel describe the channels used by the default configuration\n        while let Some(message) = server.receive_message(client_id, DefaultChannel::ReliableOrdered) {\n            // Handle received message\n        }\n    }\n    \n    // Send a text message for all clients\n    server.broadcast_message(DefaultChannel::ReliableOrdered, \"server message\");\n\n    let client_id = ClientId::from_raw(0);\n    // Send a text message for all clients except for Client 0\n    server.broadcast_message_except(client_id, DefaultChannel::ReliableOrdered, \"server message\");\n    \n    // Send message to only one client\n    server.send_message(client_id, DefaultChannel::ReliableOrdered, \"server message\");\n \n    // Send packets to clients using the transport layer\n    transport.send_packets(\u0026mut server);\n\n    std::thread::sleep(delta_time); // Running at 60hz\n}\n```\n\n### Client\n\n```rust\nlet mut client = RenetClient::new(ConnectionConfig::default());\n\n// Setup transport layer using renet_netcode\nconst server_addr: SocketAddr = \"127.0.0.1:5000\".parse().unwrap();\nlet socket = UdpSocket::bind(\"127.0.0.1:0\").unwrap();\nlet current_time = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap();\nlet authentication = ClientAuthentication::Unsecure {\n    server_addr,\n    client_id: 0,\n    user_data: None,\n    protocol_id: 0,\n};\n\nlet mut transport = NetcodeClientTransport::new(current_time, authentication, socket).unwrap();\n\n// Your gameplay loop\nloop {\n    let delta_time = Duration::from_millis(16);\n    // Receive new messages and update client\n    client.update(delta_time);\n    transport.update(delta_time, \u0026mut client).unwrap();\n    \n    if client.is_connected() {\n        // Receive message from server\n        while let Some(message) = client.receive_message(DefaultChannel::ReliableOrdered) {\n            // Handle received message\n        }\n        \n        // Send message\n        client.send_message(DefaultChannel::ReliableOrdered, \"client text\");\n    }\n \n    // Send packets to server using the transport layer\n    transport.send_packets(\u0026mut client)?;\n    \n    std::thread::sleep(delta_time); // Running at 60hz\n}\n```\n\n## Transport Layers\n\nCheckout [renet_netcode](https://github.com/lucaspoffo/renet/tree/master/renet_netcode) if you want to use  UDP with the [netcode](https://github.com/lucaspoffo/renet/tree/master/renetcode) protocol.\n\nCheckout [renet_steam](https://github.com/lucaspoffo/renet/tree/master/renet_steam) if you want to use the steam transport layer.\n\n## Demos\n\nYou can checkout the [echo example](https://github.com/lucaspoffo/renet/blob/master/renet/examples/echo.rs) for a simple usage of the library. Usage:\n\n- Server: `cargo run --example echo -- server 5000`\n- Client: `cargo run --example echo -- client 127.0.0.1:5000 CoolNickName`\n\nOr you can look into the two demos that have more complex uses of renet:\n\n\u003cdetails\u003e\u003csummary\u003eBevy Demo\u003c/summary\u003e\n\u003cbr/\u003e\nSimple bevy application to demonstrate how you could replicate entities and send reliable messages as commands from the server/client using renet:\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n[Bevy Demo.webm](https://user-images.githubusercontent.com/35241085/180664609-f8c969e0-d313-45c0-9c04-8a116896d0bd.webm)\n\n[Repository](https://github.com/lucaspoffo/renet/tree/master/demo_bevy)\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eChat Demo\u003c/summary\u003e\n\u003cbr/\u003e\nSimple chat application made with egui to demonstrate how you could handle errors, states transitions and client self hosting:\n\u003cbr/\u003e\n\u003cbr/\u003e\n\n[Chat Demo.webm](https://user-images.githubusercontent.com/35241085/180664911-0baf7b35-c9d4-43ff-b793-5955060adebc.webm)\n\n[Repository](https://github.com/lucaspoffo/renet/tree/master/demo_chat)\n\u003c/details\u003e\n\n## Plugins\n\nCheckout [bevy_renet](https://github.com/lucaspoffo/renet/tree/master/bevy_renet) if you want to use renet as a plugin with the [Bevy engine](https://bevyengine.org/).\n\n## Visualizer\n\nCheckout [renet_visualizer](https://github.com/lucaspoffo/renet/tree/master/renet_visualizer) for a egui plugin to plot metrics data from renet clients and servers:\n\nhttps://user-images.githubusercontent.com/35241085/175834010-b1eafd77-7ea2-47dc-a915-a399099c7a99.mp4\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucaspoffo%2Frenet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucaspoffo%2Frenet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucaspoffo%2Frenet/lists"}