I have a tiny service that listens on a UDP port, does seomething with the received data and rebroadcasts it to the subscribed clients. In principle, it looks like this:
let socket = UdpSocket::bind("0.0.0.0:7373")?;
socket.set_read_timeout(None).unwrap();
loop {
// listen on socket for incoming pakets (socket.recv_from)
// do something with the data
// rebroadcast the data to subscribed clients
}
So far, this works very well. I'm not a networking expert, but I guess I have to send keepalive messages in order to avoid NAT-timeouts. Is there an ideomatic way of how to implement these keepalive-pakets? I think, in Python, you can set a timeout on the socket and catch an appropriate exception. But what is the Rust-way of doing that?