use std::net::UdpSocket; use tokio::task; pub(crate) struct UdpServer; impl UdpServer { pub(crate) fn init() { match UdpSocket::bind("127.0.0.1:12345") { Ok(socket) => { task::spawn(async move { loop { let mut buf = [0; 1500]; let (amt, src) = socket.recv_from(&mut buf).unwrap(); log::info!("Received message from client {src}"); // TODO: Process received data in an independent method. let buf = &buf[..amt]; socket.send_to(buf, src).unwrap(); } }); } Err(e) => log::error!("Failed to bind to address: {e}"), } } }