mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8220585: Incorrect code in MulticastSocket sample code
Sample code shows that String.length() can be passed to a DatagramPacket along with String.getBytes(), but is incorrect for non-ASCII Strings. Reviewed-by: martin, chegar
This commit is contained in:
parent
1bfa5cee8c
commit
8c5313aa79
1 changed files with 3 additions and 2 deletions
|
@ -52,8 +52,9 @@ import java.util.Set;
|
||||||
* InetAddress group = InetAddress.getByName("228.5.6.7");
|
* InetAddress group = InetAddress.getByName("228.5.6.7");
|
||||||
* MulticastSocket s = new MulticastSocket(6789);
|
* MulticastSocket s = new MulticastSocket(6789);
|
||||||
* s.joinGroup(group);
|
* s.joinGroup(group);
|
||||||
* DatagramPacket hi = new DatagramPacket(msg.getBytes(), msg.length(),
|
* byte[] msgBytes = msg.getBytes(StandardCharsets.UTF_8);
|
||||||
* group, 6789);
|
* DatagramPacket hi = new DatagramPacket(msgBytes, msgBytes.length,
|
||||||
|
* group, 6789);
|
||||||
* s.send(hi);
|
* s.send(hi);
|
||||||
* // get their responses!
|
* // get their responses!
|
||||||
* byte[] buf = new byte[1000];
|
* byte[] buf = new byte[1000];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue