Code example for ServerSocket

Methods: bind, close, getLocalPort, getLocalSocketAddress

0
                                portNumber)));
        theSocket.close();
 
        // now create a socket that is not bound and validate we get the 
        // right answer 
        theSocket = new ServerSocket();
        assertNull(
                "Returned incorrect InetSocketAddress -unbound socket- Expected null", 
                theSocket.getLocalSocketAddress());
 
        // now bind the socket and make sure we get the right answer 
        theSocket
                .bind(new InetSocketAddress(InetAddress.getLocalHost(), 0));
        int localPort = theSocket.getLocalPort();
        assertEquals("Returned incorrect InetSocketAddress(2):", theSocket
                .getLocalSocketAddress(), new InetSocketAddress(InetAddress
                .getLocalHost(), localPort));
        theSocket.close();
    } 
 
    /** 
     * @tests java.net.ServerSocket#isBound() 
     */