Class SocketChecker

java.lang.Object
org.kiwiproject.net.SocketChecker

public class SocketChecker extends Object
Utilities for checking sockets.
  • Field Details

    • DEFAULT_TIMEOUT

      public static final Duration DEFAULT_TIMEOUT
  • Constructor Details

    • SocketChecker

      public SocketChecker()
  • Method Details

    • canConnectViaSocket

      public boolean canConnectViaSocket(String host, int port)
      Check whether a Socket can be opened on the specified host and port.
      Parameters:
      host - the host to check
      port - the port to check
      Returns:
      true if the port is open; false otherwise
    • canConnectViaSocket

      public boolean canConnectViaSocket(String host, int port, Duration timeout)
      Check whether a Socket can be opened on the specified host and port, with the specified timeout.
      Parameters:
      host - the host to check
      port - the port to check
      timeout - how long to wait for the socket connection before timing out
      Returns:
      true if the socket connection succeeded; false otherwise
    • canConnectViaSocket

      public boolean canConnectViaSocket(org.apache.commons.lang3.tuple.Pair<String,Integer> hostAndPort)
      Check whether a Socket can be opened on the specified host and port. Uses the default timeout of DEFAULT_TIMEOUT.
      Parameters:
      hostAndPort - a Pair containing the host and port to check
      Returns:
      true if the socket connection succeeded; false otherwise
    • canConnectViaSocket

      public boolean canConnectViaSocket(org.apache.commons.lang3.tuple.Pair<String,Integer> hostAndPort, Duration timeout)
      Check whether a Socket can be opened on the specified host and port, with the specified timeout.
      Parameters:
      hostAndPort - a Pair containing the host and port to check
      timeout - how long to wait for the socket connection before timing out
      Returns:
      true if the socket connection succeeded; false otherwise