2 unstable releases

0.2.0 Nov 21, 2023
0.1.0 Nov 18, 2023

#115 in #async-await

39 downloads per month
Used in 2 crates (via atm0s-media-server-transp…)

MIT license

21KB
382 lines

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

Dependencies

~0–11MB
~118K SLoC