Code example for DatagramSocket

Methods: connect, getBroadcast, setBroadcast

0
        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 { 
            theSocket.connect(new InetSocketAddress(InetAddress.getByAddress(theBytes), ports[1]));
            assertFalse("No exception when connecting to broadcast address with setBroadcast(false)", theSocket.getBroadcast());
        } catch (Exception ex) {
        } 
 
        // now validate that we can connect to the broadcast address when 
        // setBroadcast is true 
        theSocket.setBroadcast(true);
        theSocket.connect(new InetSocketAddress(InetAddress.getByAddress(theBytes), ports[2]));
    } 
 
    public void test_getBroadcast() throws Exception { 
        DatagramSocket theSocket = new DatagramSocket();
        theSocket.setBroadcast(true);