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
@ -52,8 +52,9 @@ import java.util.Set;
|
||||
* InetAddress group = InetAddress.getByName("228.5.6.7");
|
||||
* MulticastSocket s = new MulticastSocket(6789);
|
||||
* s.joinGroup(group);
|
||||
* DatagramPacket hi = new DatagramPacket(msg.getBytes(), msg.length(),
|
||||
* group, 6789);
|
||||
* byte[] msgBytes = msg.getBytes(StandardCharsets.UTF_8);
|
||||
* DatagramPacket hi = new DatagramPacket(msgBytes, msgBytes.length,
|
||||
* group, 6789);
|
||||
* s.send(hi);
|
||||
* // get their responses!
|
||||
* byte[] buf = new byte[1000];
|
||||
|
Loading…
x
Reference in New Issue
Block a user