public final class Networking extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
IP_REGEX
Regex to match an IP Address.
|
static int |
PREFERRED_OPEN_PORT_RANGE_END
The inclusive upper bound for the preferred open-port range.
|
static int |
PREFERRED_OPEN_PORT_RANGE_START
The inclusive lower bound for the preferred open-port range.
|
| Modifier and Type | Method and Description |
|---|---|
static int |
getCompanionPort(int port)
Deprecated.
|
static int |
getCompanionPort(int port,
int rounds)
Deprecated.
|
static String |
getIpAddress(String host)
Get the accessible IP Address for the
host. |
static int |
getOpenPort()
Deprecated.
use
getPreferredOpenPort() instead |
static int |
getOpenPortWithinRange(int rangeStart,
int rangeEnd)
Return an available port on the local machine in the inclusive range from
rangeStart to rangeEnd. |
static int |
getPreferredOpenPort()
Return an available port on the local machine in the preferred range.
|
static boolean |
isLocalHost(String host)
Return
true if the host belongs to the local machine. |
public static final int PREFERRED_OPEN_PORT_RANGE_START
public static final int PREFERRED_OPEN_PORT_RANGE_END
public static final String IP_REGEX
@Deprecated public static int getCompanionPort(int port)
port.port - @Deprecated public static int getCompanionPort(int port, int rounds)
port.port - rounds - public static String getIpAddress(String host)
host.host - @Deprecated public static int getOpenPort()
getPreferredOpenPort() insteadpublic static int getOpenPortWithinRange(int rangeStart,
int rangeEnd)
rangeStart to rangeEnd.
Use this method when callers must constrain selection to a specific port
range while still relying on Networking to enforce availability.
rangeStart - the first port in the allowed range (inclusive)rangeEnd - the last port in the allowed range (inclusive)IllegalArgumentException - if rangeStart <= 0,
rangeEnd < rangeStart, or
rangeEnd > public static int getPreferredOpenPort()
public static boolean isLocalHost(String host)
true if the host belongs to the local machine.host - true if the host is local