spring-framework / org.springframework.util / SocketUtils / findAvailableTcpPort

findAvailableTcpPort

open static fun findAvailableTcpPort(): Int

Find an available TCP port randomly selected from the range [{@value #PORT_RANGE_MIN}, {@value #PORT_RANGE_MAX}].

Exceptions

IllegalStateException - if no available port could be found

Return
an available TCP port number

open static fun findAvailableTcpPort(minPort: Int): Int

Find an available TCP port randomly selected from the range [minPort, {@value #PORT_RANGE_MAX}].

Parameters

minPort - the minimum port number

Exceptions

IllegalStateException - if no available port could be found

Return
an available TCP port number

open static fun findAvailableTcpPort(minPort: Int, maxPort: Int): Int

Find an available TCP port randomly selected from the range [minPort, maxPort].

Parameters

minPort - the minimum port number

maxPort - the maximum port number

Exceptions

IllegalStateException - if no available port could be found

Return
an available TCP port number