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

findAvailableTcpPorts

open static fun findAvailableTcpPorts(numRequested: Int): SortedSet<Int>

Find the requested number of available TCP ports, each randomly selected from the range [{@value #PORT_RANGE_MIN}, {@value #PORT_RANGE_MAX}].

Parameters

numRequested - the number of available ports to find

Exceptions

IllegalStateException - if the requested number of available ports could not be found

Return
a sorted set of available TCP port numbers

open static fun findAvailableTcpPorts(numRequested: Int, minPort: Int, maxPort: Int): SortedSet<Int>

Find the requested number of available TCP ports, each randomly selected from the range [minPort, maxPort].

Parameters

numRequested - the number of available ports to find

minPort - the minimum port number

maxPort - the maximum port number

Exceptions

IllegalStateException - if the requested number of available ports could not be found

Return
a sorted set of available TCP port numbers