Finds currently available server ports within a certain port range. Code originally taken from Apache MINA. Note: If possible, it's preferable to let the party creating the server socket select the port (e.g. with new ServerSocket(0)) and then query it for the port chosen. With this class, there is always a risk that someone else grabs the port between the time it is returned from getNextAvailable() and the time the socket is created.
Type Params | Return Type | Name and description |
---|---|---|
|
static AvailablePortFinder |
createPrivate() Creates a port finder that operates on private ports. |
|
int |
getNextAvailable() Gets the next available port. |
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Creates a port finder that operates on private ports.
Gets the next available port.
Tries to avoid returning the same port on successive invocations (but it may happen if no other available ports are found).