udp_sas_async

Crates.ioudp_sas_async
lib.rsudp_sas_async
version0.2.0
sourcesrc
created_at2023-11-18 10:18:20.804484
updated_at2023-11-21 10:35:58.561207
descriptionSource address selection for UDP sockets
homepage
repositoryhttps://github.com/giangndm/udp_sas_async
max_upload_size
id1040422
size48,602
giangndm (giangndm)

documentation

README

udp_sas_async

Crates.io

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();
    }
}
Commit count: 7

cargo fmt