|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.wst.server.core.util.SocketUtil
public class SocketUtil
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.
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 |
---|
public static int findUnusedPort(int low, int high)
low
- lowest possible port numberhigh
- highest possible port number
-1
if no used ports could be foundpublic static boolean isPortInUse(int port, int count)
true
if the given port is in use, and false
otherwise. Retries every 500ms for "count" tries.
port
- the port number to checkcount
- the number of times to retry
true
if the port is in use, and
false
otherwisepublic static boolean isPortInUse(int port)
true
if the given port is in use, and false
otherwise.
port
- the port number to check
true
if the port is in use, and
false
otherwisepublic static boolean isLocalhost(java.lang.String host)
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.
host
- a hostname or IP address
true
if the given host is localhost, and
false
otherwise
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |