private static int getOpenPort() throws IOException {
        Log.info(c, "getOpenPort", "Entry.");
        ServerSocket s = new ServerSocket(0);
        Log.info(c, "getOpenPort", "Got socket.");
        int port = s.getLocalPort();
        Log.info(c, "getOpenPort", "Got port " + s);
        s.close();
        Log.info(c, "getOpenPort", "Close socket");
        return port;
    }
private static int getOpenPort ( ) throws IOException { Log . info ( c , "getOpenPort" , "Entry." ) ; ServerSocket s = new ServerSocket ( 0 ) ; Log . info ( c , "getOpenPort" , "Got socket." ) ; int port = s . getLocalPort ( ) ; Log . info ( c , "getOpenPort" , "Got port " + s ) ; s . close ( ) ; Log . info ( c , "getOpenPort" , "Close socket" ) ; return port ; }
Get a free port.

@return The free port.
@throws IOException If a free port could not be found.