public class Sockets extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
PORT_RANGE_MAX
The default maximum value for port ranges used when finding an available
socket port.
|
static int |
PORT_RANGE_MIN
The default minimum value for port ranges used when finding an available
socket port.
|
| 构造器和说明 |
|---|
Sockets() |
| 限定符和类型 | 方法和说明 |
|---|---|
static int |
findAvailableTcpPort()
|
static int |
findAvailableTcpPort(int minPort)
Find an available TCP port randomly selected from the range
[
minPort, 65535]. |
static int |
findAvailableTcpPort(int minPort,
int maxPort)
Find an available TCP port randomly selected from the range
[
minPort, maxPort]. |
static SortedSet<Integer> |
findAvailableTcpPorts(int numRequested)
|
static SortedSet<Integer> |
findAvailableTcpPorts(int numRequested,
int minPort,
int maxPort)
Find the requested number of available TCP ports, each randomly selected
from the range [
minPort, maxPort]. |
static int |
findAvailableUdpPort()
|
static int |
findAvailableUdpPort(int minPort)
Find an available UDP port randomly selected from the range
[
minPort, 65535]. |
static int |
findAvailableUdpPort(int minPort,
int maxPort)
Find an available UDP port randomly selected from the range
[
minPort, maxPort]. |
static SortedSet<Integer> |
findAvailableUdpPorts(int numRequested)
|
static SortedSet<Integer> |
findAvailableUdpPorts(int numRequested,
int minPort,
int maxPort)
Find the requested number of available UDP ports, each randomly selected
from the range [
minPort, maxPort]. |
public static final int PORT_RANGE_MIN
public static final int PORT_RANGE_MAX
public static int findAvailableTcpPort()
IllegalStateException - if no available port could be foundpublic static int findAvailableTcpPort(int minPort)
minPort, 65535].minPort - the minimum port numberIllegalStateException - if no available port could be foundpublic static int findAvailableTcpPort(int minPort,
int maxPort)
minPort, maxPort].minPort - the minimum port numbermaxPort - the maximum port numberIllegalStateException - if no available port could be foundpublic static SortedSet<Integer> findAvailableTcpPorts(int numRequested)
numRequested - the number of available ports to findIllegalStateException - if the requested number of available ports could not be foundpublic static SortedSet<Integer> findAvailableTcpPorts(int numRequested, int minPort, int maxPort)
minPort, maxPort].numRequested - the number of available ports to findminPort - the minimum port numbermaxPort - the maximum port numberIllegalStateException - if the requested number of available ports could not be foundpublic static int findAvailableUdpPort()
IllegalStateException - if no available port could be foundpublic static int findAvailableUdpPort(int minPort)
minPort, 65535].minPort - the minimum port numberIllegalStateException - if no available port could be foundpublic static int findAvailableUdpPort(int minPort,
int maxPort)
minPort, maxPort].minPort - the minimum port numbermaxPort - the maximum port numberIllegalStateException - if no available port could be foundpublic static SortedSet<Integer> findAvailableUdpPorts(int numRequested)
numRequested - the number of available ports to findIllegalStateException - if the requested number of available ports could not be foundpublic static SortedSet<Integer> findAvailableUdpPorts(int numRequested, int minPort, int maxPort)
minPort, maxPort].numRequested - the number of available ports to findminPort - the minimum port numbermaxPort - the maximum port numberIllegalStateException - if the requested number of available ports could not be foundCopyright © 2021. All rights reserved.