5 个版本 (3 个破坏性更新)
0.4.0 | 2024 年 5 月 4 日 |
---|---|
0.3.0 | 2024 年 5 月 4 日 |
0.2.1 | 2024 年 5 月 4 日 |
0.2.0 | 2024 年 5 月 4 日 |
0.1.0 | 2024 年 5 月 4 日 |
#1080 in 网络编程
用于 3 crates
6KB
65 行
tinyudp

Rust 中 UDP 的小型抽象
概述
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);
},
};
依赖项
~130KB