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

#968 in Network programming

Download history 220/week @ 2024-04-28 63/week @ 2024-05-05

283 downloads per month
Used in 2 crates

MIT license

6KB
65 lines

tinyudp Test crates docs.rs

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

~130KB