Package org.ghost4j.util
Class NetworkUtil
java.lang.Object
org.ghost4j.util.NetworkUtil
Network utilities class.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic int
findAvailablePort
(String hostname, int startPort, int endPort) Finds an available port within a port range on a hoststatic void
waitUntilPortListening
(String hostname, int port, int timeout) Waits until a port is listening on a given host.
-
Constructor Details
-
NetworkUtil
public NetworkUtil()
-
-
Method Details
-
findAvailablePort
Finds an available port within a port range on a host- Parameters:
hostname
- Host namestartPort
- Port number starting the rangeendPort
- Port number ending the range- Returns:
- An available port number, or 0 if none is available.
-
waitUntilPortListening
public static void waitUntilPortListening(String hostname, int port, int timeout) throws IOException Waits until a port is listening on a given host. An exception is thrown if the timeout is excedeed.- Parameters:
hostname
- Host nameport
- Port numbertimeout
- Timeout in seconds- Throws:
IOException
- If a connection error occurs or if the timeout is exceeded
-