Overview | Package | Class | Use | Tree | Serialized | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.eclipse.wst.server.core.util
Class SocketUtil

    java.lang.Object
      org.eclipse.wst.server.core.util.SocketUtil

    public class SocketUtil

extends java.lang.Object

A utility class for socket-related function. It's main purposes are to find unused ports, check whether a port is in use, and check whether a given address is a local(host) address.

Since:
  1.0

Method Summary
`static int` | `findUnusedPort(int low, int high)` Finds an unused port between the given from and to values.
`static boolean` | `isLocalhost(java.lang.String host)` Checks if the given host (name, fully qualified name, or IP address) is referring to the local machine.
`static boolean` | `isPortInUse(int port)` Checks to see if the given port number is being used.
`static boolean` | `isPortInUse(int port, int count)` Checks to see if the given port number is being used.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### findUnusedPort

    public static int findUnusedPort(int low,
                                     int high)

  Finds an unused port between the given from and to values.

  Parameters:
    `low` - lowest possible port number
    `high` - highest possible port number
  Returns:
    an unused port number, or `-1` if no used ports could be found

### isPortInUse

    public static boolean isPortInUse(int port,
                                      int count)

  Checks to see if the given port number is being used. Returns `true` if the given port is in use, and `false` otherwise. Retries every 500ms for "count" tries.

  Parameters:
    `port` - the port number to check
    `count` - the number of times to retry
  Returns:
    boolean `true` if the port is in use, and `false` otherwise

### isPortInUse

    public static boolean isPortInUse(int port)

  Checks to see if the given port number is being used. Returns `true` if the given port is in use, and `false` otherwise.

  Parameters:
    `port` - the port number to check
  Returns:
    boolean `true` if the port is in use, and `false` otherwise

### isLocalhost

    public static boolean isLocalhost(java.lang.String host)

  Checks if the given host (name, fully qualified name, or IP address) is referring to the local machine.

  The first time this method is called (or the first call after each time the network configuration has changed, e.g. by the user switching from a wired connection to wireless) a background process is used to cache the network information. On most machines the network information will be found quickly and the results of this call will be returned immediately.

  On machines where the network configuration of the machine is bad or the network has problems, this first method call will take at most 250ms, but the results may be incorrect (incomplete).

  All subsequent calls (until the network configuration changes) will return very quickly. If the background process is still running it will continue to fill the cache and each subsequent call to this method may be more correct.

  Parameters:
    `host` - a hostname or IP address
  Returns:
    `true` if the given host is localhost, and `false` otherwise

Overview | Package | Class | Use | Tree | Serialized | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD