Code example for MulticastSocket

Methods: getInterface, setInterface, setNetworkInterface

0
		int groupPort = Support_PortManager.getNextPortForUDP();
 
                if (atLeastOneInterface) {
                        // validate that we get the expected response when one was not 
                        // set 
                        mss = new MulticastSocket(groupPort);
                        String preferIPv4StackValue = System
                                        .getProperty("java.net.preferIPv4Stack");
                        String preferIPv6AddressesValue = System
                                        .getProperty("java.net.preferIPv6Addresses");
                        if (((preferIPv4StackValue == null) || preferIPv4StackValue
                                        .equalsIgnoreCase("false"))
                                        && (preferIPv6AddressesValue != null)
                                        && (preferIPv6AddressesValue.equals("true"))) {
                                // we expect an IPv6 ANY in this case 
                                assertEquals("inet Address returned when not set", 
                                             InetAddress.getByName("::0"),
                                             mss.getInterface());
                        } else { 
                                // we expect an IPv4 ANY in this case 
                                assertEquals("inet Address returned when not set", 
                                             InetAddress.getByName("0.0.0.0"),
                                             mss.getInterface());
                        } 
 
                        // validate that we get the expected response when we set via 
                        // setInterface 
                        Enumeration addresses = networkInterface1.getInetAddresses();
                        if (addresses.hasMoreElements()) {
                                InetAddress firstAddress = (InetAddress) addresses
                                                .nextElement();
                                mss.setInterface(firstAddress);
                                assertEquals("getNetworkInterface did not return interface set by setInterface", 
                                             firstAddress, mss.getInterface());
 
                                groupPort = Support_PortManager.getNextPortForUDP();
                                mss = new MulticastSocket(groupPort);
                                mss.setNetworkInterface(networkInterface1);
                                assertEquals("getInterface did not return interface set by setNetworkInterface",