Crates.io | tinyudp |
lib.rs | tinyudp |
version | 0.4.0 |
source | src |
created_at | 2024-05-04 07:59:26.29125 |
updated_at | 2024-05-04 14:13:25.942051 |
description | A tiny abstraction for UDP. |
homepage | |
repository | https://github.com/vikpe/tinyudp |
max_upload_size | |
id | 1229453 |
size | 5,428 |
A tiny abstraction for UDP in Rust
tinyudp::send(address: impl ToSocketAddrs, message: &[u8]) -> Result<usize>
tinyudp::read(address: impl ToSocketAddrs, options: &ReadOptions) -> Result<Vec<u8>>
tinyudp::send_and_read(address: impl ToSocketAddrs, message: &[u8], read_options: &ReadOptions) -> Result<Vec<u8>>
struct ReadOptions {
pub timeout: Option<Duration>,
pub buffer_size: usize,
}
tinyudp::send("quake.se:28000", &b"hello")?;
let options = tinyudp::ReadOptions{
timeout: Some(Duration::from_secs(1)),
buffer_size: 8 * 1024,
};
let response = tinyudp::read("quake.se:28000", &options)?;
let options = tinyudp::ReadOptions{
timeout: Some(Duration::from_secs(1)),
buffer_size: 8 * 1024,
};
match tinyudp::send_and_read("quake.se:28000", &b"hello", &options) {
Ok(response) => {
println!("response: {:?}", response);
},
Err(e) => {
println!("error: {:?}", e);
},
};