@@ -598,8 +598,11 @@ impl UdpSocket {
598
598
/// receive data from the specified address.
599
599
///
600
600
/// If `addr` yields multiple addresses, `connect` will be attempted with
601
- /// each of the addresses until a connection is successful. If none of
602
- /// the addresses are able to be connected, the error returned from the
601
+ /// each of the addresses until the underlying OS function returns no
602
+ /// error. Note that usually, a successful `connect` call does not specify
603
+ /// that there is a remote server listening on the port, rather, such an
604
+ /// error would only be detected after the first send. If the OS returns an
605
+ /// error for each of the specified addresses, the error returned from the
603
606
/// last connection attempt (the last address) is returned.
604
607
///
605
608
/// # Examples
@@ -614,20 +617,10 @@ impl UdpSocket {
614
617
/// socket.connect("127.0.0.1:8080").expect("connect function failed");
615
618
/// ```
616
619
///
617
- /// Create a UDP socket bound to `127.0.0.1:3400` and connect the socket to
618
- /// `127.0.0.1:8080`. If that connection fails, then the UDP socket will
619
- /// connect to `127.0.0.1:8081`:
620
- ///
621
- /// ```no_run
622
- /// use std::net::{SocketAddr, UdpSocket};
623
- ///
624
- /// let socket = UdpSocket::bind("127.0.0.1:3400").expect("couldn't bind to address");
625
- /// let connect_addrs = [
626
- /// SocketAddr::from(([127, 0, 0, 1], 8080)),
627
- /// SocketAddr::from(([127, 0, 0, 1], 8081)),
628
- /// ];
629
- /// socket.connect(&connect_addrs[..]).expect("connect function failed");
630
- /// ```
620
+ /// Unlike in the TCP case, passing an array of addresses to the `connect`
621
+ /// function of a UDP socket is not a useful thing to do: The OS will be
622
+ /// unable to determine whether something is listening on the remote
623
+ /// address without the application sending data.
631
624
#[ stable( feature = "net2_mutators" , since = "1.9.0" ) ]
632
625
pub fn connect < A : ToSocketAddrs > ( & self , addr : A ) -> io:: Result < ( ) > {
633
626
super :: each_addr ( addr, |addr| self . 0 . connect ( addr) )
0 commit comments