UdpSocket weird binding behaviour

I'm trying to use the below code, but the connect(remote_addr) fail (error message below).
But it work fine when I use UdpSocket::bind(""). and [::]:0 aren't supposed to be the same thing ?

I don't know if it's a rust-specific issue or just how network work, but I would appreciate an explanation :sweat_smile:.

    let remote_addr: SocketAddr = "".parse().expect("could not parse addr");
    let socket = UdpSocket::bind("[::]:0").expect("could not bind socket");
        .expect("could not connect to server");
thread 'main' panicked at 'could not connect to server: Os { code: 10014, kind: Uncategorized, message: "Le système a détecté une adresse de pointeur non valide en essayant d’utiliser un argument pointeur dans un appel." }'

You know, the one is a IPv4 address and the other is a IPv6 address. :slight_smile:

This distinction matter. is a IPv4 unspecified address. Binding the socket on it means to listen every IPv4 network interfaces - yes, IPv4 interfaces. IPv4 and IPv6 do not share network interfaces on its own. To connect to the IPv6 loopback interface, use [::1]:4567 instead which is a IPv6 locahost address.


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.