Code example for DatagramSocket

Methods: bind, close, isBound

0
        theSocket.close();
 
        // now test when we bind explicitely 
        InetSocketAddress theLocalAddress = new InetSocketAddress(InetAddress
                .getLocalHost(), ports[2]);
        theSocket = new DatagramSocket(null);
        assertFalse("Socket indicated bound when it should not be (2)",
                theSocket.isBound());
        theSocket.bind(theLocalAddress);
        assertTrue("Socket indicated not bound when it should be (4)",
                theSocket.isBound());
        theSocket.close();
        assertTrue("Socket indicated not bound when it should be (5)",
                theSocket.isBound());
    } 
 
    /** 
     * @tests java.net.DatagramSocket#isConnected() 
     */ 
    public void test_isConnected() throws Exception { 
        InetAddress addr = InetAddress.getLocalHost();