Why OS error 22 on UdpSocket send?

Why does the following code produce the error at the bottom? What am I missing or doing wrong?
Some equivalent Python code works as expected. Also, the error is not very helpful

    let my_addr = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 13001);
    let socket = UdpSocket::bind(my_addr)?;
    let addr = SocketAddrV4::new(Ipv4Addr::new(46, 226, 106, 127), 52099);
    let buf = "foobar".as_bytes();
    socket.send_to(buf, addr)?;
Error: Os { code: 22, kind: InvalidInput, message: "Invalid argument" }

Binding to 127.0.0.1 is probably not what you want; that's the loopback interface so you can probably only send messages to yourself. Try binding to 0.0.0.0 instead.

Right (face palm)! Thanks!

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.