Crates.io | udp_sas_async |
lib.rs | udp_sas_async |
version | 0.2.0 |
source | src |
created_at | 2023-11-18 10:18:20.804484 |
updated_at | 2023-11-21 10:35:58.561207 |
description | Source address selection for UDP sockets |
homepage | |
repository | https://github.com/giangndm/udp_sas_async |
max_upload_size | |
id | 1040422 |
size | 48,602 |
This project implement async support with both tokio or async_std for udp_sas crate (https://crates.io/crates/udp_sas)
Example with tokio
use udp_sas_async::tokio::UdpSocketSas;
#[tokio::main]
async fn main() {
let socket = UdpSocketSas::bind("0.0.0.0:0".parse().unwrap()).unwrap();
println!("Running port on 0.0.0.0:{}", socket.local_port());
let mut buf = [0; 1500];
while let Ok((size, remote, dest)) = socket.recv_sas(&mut buf).await {
println!("received {} from {} to {}", size, remote, dest);
socket.send_sas(&buf[..size], dest, remote).await.unwrap();
}
}
Example with async_std
use udp_sas_async::async_std::UdpSocketSas;
#[tokio::main]
async fn main() {
let socket = UdpSocketSas::bind("0.0.0.0:0".parse().unwrap()).unwrap();
println!("Running port on 0.0.0.0:{}", socket.local_port());
let mut buf = [0; 1500];
while let Ok((size, remote, dest)) = socket.recv_sas(&mut buf).await {
println!("received {} from {} to {}", size, remote, dest);
socket.send_sas(&buf[..size], dest, remote).await.unwrap();
}
}