int[] ports = Support_PortManager.getNextPortsForUDP(2);
int groupPort = ports[0];
int serverPort = ports[1];
if (atLeastOneInterface) {
// validate that null interface is handled ok
mss = new MulticastSocket(groupPort);
// this should through a socket exception to be compatible
try {
mss.setNetworkInterface(null);
fail("No socket exception when we set then network interface with NULL");
} catch (SocketException ex) {
}
// validate that we can get and set the interface
groupPort = Support_PortManager.getNextPortForUDP();
mss = new MulticastSocket(groupPort);
mss.setNetworkInterface(networkInterface1);
assertTrue(
"Interface did not seem to be set by setNeworkInterface",
networkInterface1.equals(mss.getNetworkInterface()));
// set up the server and join the group
group = InetAddress.getByName("224.0.0.3");
Enumeration theInterfaces = NetworkInterface.getNetworkInterfaces();
while (theInterfaces.hasMoreElements()) {
NetworkInterface thisInterface = (NetworkInterface) theInterfaces
.nextElement();
if (thisInterface.getInetAddresses() != null
&& thisInterface.getInetAddresses().hasMoreElements()) {
if ((!((InetAddress) thisInterface.getInetAddresses()
.nextElement()).isLoopbackAddress())
&&
// for windows we cannot use these pseudo
// interfaces for the test as the packets still
// come from the actual interface, not the
// Pseudo interface that was set
(Support_NetworkInterface
.useInterface(thisInterface) == true)) {
ports = Support_PortManager.getNextPortsForUDP(2);
serverPort = ports[0];
server = new MulticastServer(group, serverPort);
server.start();
// give the server some time to start up
Thread.sleep(1000);
// Send the packets on a particular interface. The
// source address in the received packet
// should be one of the addresses for the interface
// set
groupPort = ports[1];
mss = new MulticastSocket(groupPort);
mss.setNetworkInterface(thisInterface);
msg = thisInterface.getName();
byte theBytes[] = msg.getBytes();
DatagramPacket sdp = new DatagramPacket(theBytes,
theBytes.length, group, serverPort);