Code example for DatagramSocket

Methods: getReuseAddress, setReuseAddress

0
            theSocket2.close();
        } 
    } 
 
    public void test_getReuseAddress() throws Exception { 
        DatagramSocket theSocket = new DatagramSocket();
        theSocket.setReuseAddress(true);
        assertTrue("getReuseAddress false when it should be true", theSocket.getReuseAddress());
        theSocket.setReuseAddress(false);
        assertFalse("getReuseAddress true when it should be False", theSocket.getReuseAddress());
    } 
 
    public void test_setBroadcastZ() throws Exception { 
        int[] ports = Support_PortManager.getNextPortsForUDP(3);
        DatagramSocket theSocket = new DatagramSocket(ports[0]);
        theSocket.setBroadcast(false);
        byte theBytes[] = { -1, -1, -1, -1 };
 
        // validate we cannot connect to the broadcast address when 
        // setBroadcast is false 
        try {