*/
public void test2276() throws IOException {
final String ADDRESS = "239.255.2.3";
final int PORT = Support_PortManager.getNextPortForUDP();
InetAddress group = InetAddress.getByName(ADDRESS);
MulticastSocket socket = new MulticastSocket(PORT);
byte[] recvData = new byte[100];
DatagramPacket recvDatagram = new DatagramPacket(recvData, recvData.length);
String message = "Hello, world!";
String longerMessage = message + " again.";
String veryLongMessage = longerMessage + " Forever!";
socket.joinGroup(group);
socket.setSoTimeout(5000); // prevent eternal block in
// socket.receive()
// send & recieve packet
byte[] sendData = message.getBytes();
DatagramPacket sendDatagram = new DatagramPacket(sendData, 0,
sendData.length, group, PORT);
socket.send(sendDatagram);
socket.receive(recvDatagram);
String recvMessage = new String(recvData, 0, recvDatagram.getLength());
assertEquals(message, recvMessage);
// send & receive longer packet
sendData = longerMessage.getBytes();
sendDatagram = new DatagramPacket(sendData, 0, sendData.length,
group, PORT);
socket.send(sendDatagram);
socket.receive(recvDatagram);
recvMessage = new String(recvData, 0, recvDatagram.getLength());
assertEquals(longerMessage, recvMessage);
// tricky case, added to test compatibility with RI;
// depends on the previous test case
sendData = veryLongMessage.getBytes();
sendDatagram = new DatagramPacket(sendData, 0, sendData.length, group,
PORT);
socket.send(sendDatagram);
recvDatagram.setLength(recvDatagram.getLength()); // !!!
socket.receive(recvDatagram);
recvMessage = new String(recvData, 0, recvDatagram.getLength());
assertEquals(longerMessage, recvMessage);
// tests if received packet is truncated after length was set to 1
sendData = message.getBytes();
sendDatagram = new DatagramPacket(sendData, 0, sendData.length,
group, PORT);
socket.send(sendDatagram);
recvDatagram.setLength(1);
socket.receive(recvDatagram);
assertEquals("Received message was not truncated", 1,
recvDatagram.getLength());
assertSame("Received message is invalid", sendData[0], recvData[0]);
socket.leaveGroup(group);
socket.close();
}