open class SocketUtils
Simple utility methods for working with network sockets — for example, for finding available ports on localhost.
Within this class, a TCP port refers to a port for a ServerSocket; whereas, a UDP port refers to a port for a DatagramSocket.
Author
Sam Brannen
Author
Ben Hale
Author
Arjen Poutsma
Author
Gunnar Hillert
Author
Gary Russell
Since
4.0
SocketUtils()
Although Static methods from this class may be invoked from within XML configuration files using the Spring Expression Language (SpEL) and the following syntax. If this constructor were private, you would be required to supply the fully qualified class name to SpEL's T() function for each usage. Thus, the fact that this constructor is public allows you to reduce boilerplate configuration with SpEL as can be seen in the following example.
|
static val PORT_RANGE_MAX: Int
The default maximum value for port ranges used when finding an available socket port. |
|
static val PORT_RANGE_MIN: Int
The default minimum value for port ranges used when finding an available socket port. |
open static fun findAvailableTcpPort(): Int
Find an available TCP port randomly selected from the range [{@value #PORT_RANGE_MIN}, {@value #PORT_RANGE_MAX}]. open static fun findAvailableTcpPort(minPort: Int): Int
Find an available TCP port randomly selected from the range [ open static fun findAvailableTcpPort(minPort: Int, maxPort: Int): Int
Find an available TCP port randomly selected from the range [ |
|
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}]. 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 [ |
|
open static fun findAvailableUdpPort(): Int
Find an available UDP port randomly selected from the range [{@value #PORT_RANGE_MIN}, {@value #PORT_RANGE_MAX}]. open static fun findAvailableUdpPort(minPort: Int): Int
Find an available UDP port randomly selected from the range [ open static fun findAvailableUdpPort(minPort: Int, maxPort: Int): Int
Find an available UDP port randomly selected from the range [ |
|
open static fun findAvailableUdpPorts(numRequested: Int): SortedSet<Int>
Find the requested number of available UDP ports, each randomly selected from the range [{@value #PORT_RANGE_MIN}, {@value #PORT_RANGE_MAX}]. open static fun findAvailableUdpPorts(numRequested: Int, minPort: Int, maxPort: Int): SortedSet<Int>
Find the requested number of available UDP ports, each randomly selected from the range [ |