Code example for DatagramSocket

Methods: close, getLocalSocketAddress

0
                        new InetSocketAddress(InetAddress.getLocalHost(),
                                portNumber)));
        theSocket.close();
 
        // now validate thet behaviour when the any address is returned 
        s = new DatagramSocket(0);
 
        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"))) {
            assertTrue(
                    "ANY address not returned correctly with preferIPv6Addresses=true, preferIPv4Stack=false " 
                            + s.getLocalSocketAddress(),
                    ((InetSocketAddress) s.getLocalSocketAddress())
                            .getAddress() instanceof Inet6Address);
        } else { 
            assertTrue(
                    "ANY address not returned correctly with preferIPv6Addresses=true, preferIPv4Stack=true " 
                            + s.getLocalSocketAddress(),
                    ((InetSocketAddress) s.getLocalSocketAddress())
                            .getAddress() instanceof Inet4Address);
        } 
        s.close();
    } 
 
    public void test_setReuseAddressZ() throws Exception { 
        // test case were we set it to false 
        DatagramSocket theSocket1 = null;