In the documentation for MulticastSocket, the following sample code exists:
String msg = "Hello";
InetAddress group = InetAddress.getByName("228.5.6.7");
MulticastSocket s = new MulticastSocket(6789);
s.joinGroup(group);
byte[] msgBytes = msg.getBytes();
DatagramPacket hi = new DatagramPacket(msgBytes, msgBytes.length, group, 6789);
The DatagramPacket's length argument takes the byte length and String.length() returns the number of UTF-16 characters, so if a string has any non-ASCII characters s.length() != s.getBytes().length.
String msg = "Hello";
InetAddress group = InetAddress.getByName("228.5.6.7");
MulticastSocket s = new MulticastSocket(6789);
s.joinGroup(group);
byte[] msgBytes = msg.getBytes();
DatagramPacket hi = new DatagramPacket(msgBytes, msgBytes.length, group, 6789);
The DatagramPacket's length argument takes the byte length and String.length() returns the number of UTF-16 characters, so if a string has any non-ASCII characters s.length() != s.getBytes().length.