Rust UDP connection not working but netcat does

78 Views Asked by At

I'm trying to get data that is sent via udp to port 20777 on my mac. Running a listener with netcat, I'm able to receive the data: nc -u -l 0.0.0.0 20777.

However, the following rust code hangs on recv_from...

use std::net::UdpSocket;

use bytebuffer::ByteBuffer;

let socket = UdpSocket::bind("0.0.0.0:20777").expect("Failed to bind to port!");

loop {
    let mut buf = [0; 2048];
    match socket.recv_from(&mut buf) {
        Ok((size, _addr)) => {
            println!("Got {} bytes", size); 
        }
        Err(_) => println!("Failed")
    }
}

What could be causing this issue...

0

There are 0 best solutions below