Skip to main content

bind_udp_socket_with_connect

Function bind_udp_socket_with_connect 

pub async fn bind_udp_socket_with_connect<Dns>(
    address: impl Into<HostWithPort>,
    dns: Dns,
    extensions: Option<&Extensions>,
) -> Result<UdpSocket, Box<dyn Error + Send + Sync>>
where Dns: DnsAddressResolver,
Expand description

Bind a UdpSocket to the local interface and connect to the given host and port using the provided DNS resolver, in case the host is a Domain, otherwise the IpAddr will be used as-is.

The host, if a domain, is resolved using a Happy Eyeballs strategy and each resolved IP address is attempted in order until the socket successfully connects. The first successful connection attempt completes the function. The strategy also respects IP/Dns connect/resolve preferences (e.g. Ipv6 addresses won’t be allowed if running in Ipv4 only modes), even if host was an Ip to begin with.

Returns an error if the host is not compatible or does not resolve to any IP address or if all resolved addresses fail to connect.

Connecting a UDP socket configures its default remote peer and restricts incoming datagrams to that peer. It does not perform a handshake or guarantee reachability.