Use std::net::UdpSocket to bind to an address and loop with recv_from to handle incoming datagrams.
use std::net::UdpSocket;
fn main() -> std::io::Result<()> {
let socket = UdpSocket::bind("127.0.0.1:8080")?;
let mut buf = [0; 1024];
loop {
let (len, addr) = socket.recv_from(&mut buf)?;
println!("Received {} bytes from {}: {}", len, addr, String::from_utf8_lossy(&buf[..len]));
}
}