Class SocketUtils


  • public class SocketUtils
    extends java.lang.Object
    Utility methods for dealing with sockets.
    Since:
    1.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String LOCALHOST
      Constant for localhost.
      static int MAX_PORT_RANGE
      The maximum port number.
      static int MIN_PORT_RANGE
      The minimum port number.
    • Constructor Summary

      Constructors 
      Constructor Description
      SocketUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int findAvailableTcpPort()
      Finds an available TCP port.
      static int findAvailableTcpPort​(int minPortRange, int maxPortRange)
      Finds an available TCP port.
      static boolean isTcpPortAvailable​(int currentPort)
      Check whether the given TCP port is available.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOCALHOST

        public static final java.lang.String LOCALHOST
        Constant for localhost.
        See Also:
        Constant Field Values
      • MIN_PORT_RANGE

        public static final int MIN_PORT_RANGE
        The minimum port number.
        See Also:
        Constant Field Values
      • MAX_PORT_RANGE

        public static final int MAX_PORT_RANGE
        The maximum port number.
        See Also:
        Constant Field Values
    • Constructor Detail

      • SocketUtils

        public SocketUtils()
    • Method Detail

      • findAvailableTcpPort

        public static int findAvailableTcpPort()
        Finds an available TCP port.
        Returns:
        The available port
      • findAvailableTcpPort

        public static int findAvailableTcpPort​(int minPortRange,
                                               int maxPortRange)
        Finds an available TCP port.
        Parameters:
        minPortRange - The minimum port range
        maxPortRange - The maximum port range
        Returns:
        The available port
      • isTcpPortAvailable

        public static boolean isTcpPortAvailable​(int currentPort)
        Check whether the given TCP port is available.
        Parameters:
        currentPort - The port
        Returns:
        True if it is