Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
mini_udp
Overview
A minimal, fully synchronous implementation of a reliability protocol on top of UDP.
This was inspired by Glenn Fiedler, who wrote an amazing set of articles about this: https://gafferongames.com/categories/building-a-game-network-protocol/
The main entry points of this crate are UdpCommunicator
and MultiUdpCommunicator, which both wrap
std::net::UdpSocket.
All messages are (de)serialized by the in-house ByteRepr trait, which has a derive macro as well:
ByteRepr.
Features
- Derive byte representations for Enums and Structs.
- Send unreliable, reliable, or reliable ordered messages over UDP.
- Verify packet integrity using a 4-byte CRC, seeded with a user-defined protocol version.
- Messages get combined into packets, with a maximum packet size of 1024 bytes
(
MAX_PACKET_DATA_LEN). - Handle 1-X communication via a single, shared UDP socket
(
MultiUdpCommunicator). - Have a fully synchronous, non-blocking API, ideal for game networking.
- Messages cannot be fragmented yet, so it is not possible to send messages larger than 1024 bytes! (yet)
- The
ByteReprderive is not very mindful of bandwidth yet (booleans are padded to 1 byte, strings and vecs use 4 bytes to send their length as u32).
Example
use *;
/// The protocol version is used as seed for the CRC algorithm. Thus, when receiving a packet
/// that was send from a communicator with a different version, the CRC check will fail.
const PROTOCOL_VERSION: u32 = 1;
const POSITION: = ;
let mut server = bind;
// `UdpCommunicator::default()` binds the communicator to "0.0.0.0:0", which lets the OS decide
// which port to use.
let mut client =
default.connect.unwrap;
// The `write*` methods only add the message to a queue, they won't be send until you explicitly
// call `send()`.
client.write_ordered;
let mut messages_read = 0;
loop
assert_eq!;
License
All code in this repository is dual-licensed under either
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
at your option.
Contributions
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.