Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1071e82

Browse files
authored
Merge pull request #671 from Noah-Kennedy/udp-socket-send-doc
Fix docs for UdpSocket::send
2 parents 133e30e + 0a52864 commit 1071e82

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

‎src/net/udp/mod.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,12 @@ impl UdpSocket {
244244
}))
245245
}
246246

247-
/// Sends data on the socket to the given address.
247+
/// Sends data on the socket to the remote address to which it is connected.
248248
///
249-
/// On success, returns the number of bytes written.
249+
/// The [`connect`] method will connect this socket to a remote address.
250+
/// This method will fail if the socket is not connected.
251+
///
252+
/// [`connect`]: #method.connect
250253
///
251254
/// # Examples
252255
///
@@ -255,18 +258,11 @@ impl UdpSocket {
255258
/// #
256259
/// use async_std::net::UdpSocket;
257260
///
258-
/// const THE_MERCHANT_OF_VENICE: &[u8] = b"
259-
/// If you prick us, do we not bleed?
260-
/// If you tickle us, do we not laugh?
261-
/// If you poison us, do we not die?
262-
/// And if you wrong us, shall we not revenge?
263-
/// ";
264-
///
265-
/// let socket = UdpSocket::bind("127.0.0.1:0").await?;
261+
/// let socket = UdpSocket::bind("127.0.0.1:34254").await?;
262+
/// socket.connect("127.0.0.1:8080").await?;
263+
/// let bytes = socket.send(b"Hi there!").await?;
266264
///
267-
/// let addr = "127.0.0.1:7878";
268-
/// let sent = socket.send_to(THE_MERCHANT_OF_VENICE, &addr).await?;
269-
/// println!("Sent {} bytes to {}", sent, addr);
265+
/// println!("Sent {} bytes", bytes);
270266
/// #
271267
/// # Ok(()) }) }
272268
/// ```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /