15 lines
417 B
Rust
15 lines
417 B
Rust
use std::io;
|
|
use tokio::net::UdpSocket;
|
|
|
|
#[tokio::main]
|
|
async fn main() -> io::Result<()> {
|
|
let sock = UdpSocket::bind("0.0.0.0:8080").await?;
|
|
let mut buf = [0; 1024];
|
|
loop {
|
|
let (len, addr) = sock.recv_from(&mut buf).await?;
|
|
println!("{:?} bytes received from {:?}", len, addr);
|
|
|
|
let len = sock.send_to(&buf[..len], addr).await?;
|
|
println!("{:?} bytes sent", len);
|
|
}
|
|
}
|