5 releases (3 breaking)
0.4.0 | May 4, 2024 |
---|---|
0.3.0 | May 4, 2024 |
0.2.1 | May 4, 2024 |
0.2.0 | May 4, 2024 |
0.1.0 | May 4, 2024 |
#1513 in Network programming
71 downloads per month
Used in 3 crates
6KB
65 lines
tinyudp
A tiny abstraction for UDP in Rust
Overview
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,
}
Usage
Send
tinyudp::send("quake.se:28000", &b"hello")?;
Read
let options = tinyudp::ReadOptions{
timeout: Some(Duration::from_secs(1)),
buffer_size: 8 * 1024,
};
let response = tinyudp::read("quake.se:28000", &options)?;
Send and read
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);
},
};
Dependencies
~135KB