File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -161,6 +161,29 @@ impl UdpSocket {
161
161
self . inner . local_addr ( )
162
162
}
163
163
164
+ /// Returns the socket address of the remote peer this socket was connected to.
165
+ ///
166
+ /// # Examples
167
+ ///
168
+ #[ cfg_attr( feature = "os-poll" , doc = "```" ) ]
169
+ #[ cfg_attr( not( feature = "os-poll" ) , doc = "```ignore" ) ]
170
+ /// # use std::error::Error;
171
+ /// #
172
+ /// # fn main() -> Result<(), Box<dyn Error>> {
173
+ /// use mio::net::UdpSocket;
174
+ ///
175
+ /// let addr = "127.0.0.1:0".parse()?;
176
+ /// let peer_addr = "127.0.0.1:11100".parse()?;
177
+ /// let socket = UdpSocket::bind(addr)?;
178
+ /// socket.connect(peer_addr)?;
179
+ /// assert_eq!(socket.peer_addr()?.ip(), peer_addr.ip());
180
+ /// # Ok(())
181
+ /// # }
182
+ /// ```
183
+ pub fn peer_addr ( & self ) -> io:: Result < SocketAddr > {
184
+ self . inner . peer_addr ( )
185
+ }
186
+
164
187
/// Sends data on the socket to the given address. On success, returns the
165
188
/// number of bytes written.
166
189
///
You can’t perform that action at this time.
0 commit comments