public static int getNextAvailablePort ( int fromPort , int toPort ) { if ( fromPort < MIN_PORT_NUMBER || toPort > MAX_PORT_NUMBER || fromPort > toPort ) { throw new IllegalArgumentException ( format ( "Invalid port range: %d ~ %d" , fromPort , toPort ) ) ; } int nextPort = fromPort ; //noinspection StatementWithEmptyBody while ( ! isPortAvailable ( nextPort ++ ) ) { /* Empty */ } return nextPort ; }
Returns a currently available port number in the specified range .