1 use std::net::UdpSocket;
3 const MESSAGE_SIZE: usize = 12;
6 let socket = UdpSocket::bind("0.0.0.0:29803").expect("couldn't bind to address");
8 let mut buf = [0; MESSAGE_SIZE];
9 match socket.recv_from(&mut buf) {
10 Err(e) => eprintln!("Didn't receive data: {e}"),
11 Ok((number_of_bytes, src_addr)) => {
12 let filled_buf = &mut buf[..number_of_bytes];
13 if number_of_bytes != MESSAGE_SIZE {
14 eprintln!("Ignoring short message ({number_of_bytes}) from {src_addr}");
17 println!("Got packet from {src_addr}: {filled_buf:?}");