How to create a UDP server

Create a UDP server in Rust by binding a UdpSocket to an address and looping through recv_from calls to process incoming data.

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