misc: print UDP client listening message after successful socket bind

This commit is contained in:
Maciej Pędzich 2025-02-21 18:23:46 +01:00
parent 9fe4ec289d
commit d2ded9da51
Signed by: maciejpedzich
GPG Key ID: CE4A303D84882F0D

View File

@ -3,13 +3,16 @@ use std::error::Error;
use std::net::UdpSocket;
fn main() -> Result<(), Box<dyn Error>> {
let socket = UdpSocket::bind("127.0.0.1:20777")?;
let addr = "127.0.0.1:20777";
let socket = UdpSocket::bind(addr)?;
let mut buf = [0u8; 2048];
loop {
let (msg_size, _) = socket.recv_from(&mut buf)?;
let data = &buf[..msg_size];
println!("UDP client is listening on {}", addr);
parse(data)?;
loop {
let (msg_len, _) = socket.recv_from(&mut buf)?;
let msg = &buf[..msg_len];
parse(msg)?;
}
}