Does tokio::udp::UdpSocket.connect guarantee that all packets from remote_addr hit the socket?

Context: UdpSocket in tokio::net - Rust

XY problem: I want to create a udp socket, then fire off a new async task for each remote_addr that talks to the socket (with a timeout of say, kill the task if no msg for 3 minutes).

The documentation for connect states:

Connects the UDP socket setting the default destination for send() and limiting packets that are read via recv from the address specified in addr

This is great, but I need something stronger -- namely that all udp packets that are from given remote_addr are guaranteed to hit this socket.

One can imagine a layout that looks something like this:

async fn main() -> io::Result<()> {
    let sock = UdpSocket::bind("0.0.0.0:8080").await?;
    let mut buf = [0; 1024];
    loop {
        let (len, addr) = sock.recv_from(&mut buf).await?;
        creates a new task, based on remote_addr, use connect;
    }
}

My concern is: can the "recv_from" from the original sock consume packets meant for the task dedicated to remote_addr ?

The answer is whatever the OS guarantees. Note that even if the answer was yes, you would still need to handle the case where a second packet arrives before you could create the task-specific socket.

On Linux, which man pages do you recommend ?

Well, this is UDP right? We can just pretend that packet didn't arrive ...

man socket I'd say.

Fair point.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.