]> git.scottworley.com Git - tattlekey/blob - server/src/main.rs
server: Receive packets
[tattlekey] / server / src / main.rs
1 use std::net::UdpSocket;
2
3 const MESSAGE_SIZE: usize = 12;
4
5 fn main() {
6 let socket = UdpSocket::bind("0.0.0.0:29803").expect("couldn't bind to address");
7 loop {
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}");
15 continue;
16 }
17 println!("Got packet from {src_addr}: {filled_buf:?}");
18 }
19 }
20 }
21 }