Laminar
This library implements some TCP-like features on top of an UDP-socket. It will provide a lightweight message-based interface with certain guarantees like reliability, fragmentation congestion monitoring.
Laminar was designed to be used in the Amethyst game engine and is loosely based on articles from gaffer on games.
Table of contents:
Features
These are the features this crate provides:
- UDP-based protocol
- Connection tracking
- Automatic Fragmentation
- Unreliable and Reliable packets
- Protocol versioning
- RTT estimation
- Link conditioner to simulate packet loss and latency
- Well tested by integration tests and unit tests
- Good error handling
- Benchmarks
Getting Stated
Add the laminar package to your Cargo.toml
file.
[]
= "0.1"
Useful Links
Examples
These are some basic examples demonstrating how to use this crate. Please checkout our examples for more.
UDP API | see more
This is an example of how to use the UDP API.
Send packets
use ;
use ;
// Create the necessarily config, you can edit it or just use the default.
let config = default;
// Setup an udp socket and bind it to the client address.
let mut udp_socket = bind.unwrap;
// our data
let bytes = vec!;
// Create a packet that can be send with the given destination and raw data.
let packet = new;
// Or we could also use the function syntax for more clarity:
let packet = unreliable;
let packet = reliable_unordered;
// Send the packet to the endpoint we earlier placed into the packet.
udp_socket.send;
Receive Packets
use ;
use SocketAddr;
// Create the necessarily config, you can edit it or just use the default.
let config = default;
// Setup an udp socket and bind it to the client address.
let mut udp_socket = bind.unwrap;
// Start receiving (blocks the current thread), use `udp_socket.set_nonblocking()` for not blocking the current thread.
let result = udp_socket.recv;
match result
Authors
We want to give credit to gaffer on games as we have used his guide to building a game networking protocol to build this library.
Note
This library is not fully stable yet.
Although version 0.1.0 is released we might have to change some of the existing API.
Laminar is used in Amethyst-Network, you could give that a look if you want to see some more advanced use-cases.
Contribution
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.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.