Code example for DatagramSocket

Methods: getBroadcast, getLocalAddress, getLocalPort

0
 
            public UnsupportedSocketAddress() { 
            } 
        } 
 
        DatagramSocket ds = new DatagramSocket(new InetSocketAddress(
                InetAddress.getLocalHost(), 0));
        assertTrue(ds.getBroadcast());
        assertTrue("Created socket with incorrect port", ds.getLocalPort() != 0);
        assertEquals("Created socket with incorrect address", InetAddress
                .getLocalHost(), ds.getLocalAddress());
 
        try { 
            ds = new java.net.DatagramSocket(new UnsupportedSocketAddress());
            fail("No exception when constructing datagramSocket with unsupported SocketAddress type");
        } catch (IllegalArgumentException e) {
            // Expected 
        } 
 
        // regression for HARMONY-894 
        ds = new DatagramSocket((SocketAddress) null);