Class NetworkUtil

java.lang.Object
org.ghost4j.util.NetworkUtil

public class NetworkUtil extends Object
Network utilities class.
  • Constructor Details

    • NetworkUtil

      public NetworkUtil()
  • Method Details

    • findAvailablePort

      public static int findAvailablePort(String hostname, int startPort, int endPort)
      Finds an available port within a port range on a host
      Parameters:
      hostname - Host name
      startPort - Port number starting the range
      endPort - 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 name
      port - Port number
      timeout - Timeout in seconds
      Throws:
      IOException - If a connection error occurs or if the timeout is exceeded