public class PortRange extends Object
Modifier and Type | Field and Description |
---|---|
protected static byte |
UNUSED |
protected static byte |
USED |
Modifier | Constructor and Description |
---|---|
protected |
PortRange() |
Modifier and Type | Method and Description |
---|---|
void |
free(int portNumber)
Releases or frees the port number.
|
int |
getFreePort(int lastPortNumber)
Returns first available port.
|
static PortRange |
getInstance()
Returns PortRange instance for TCP listening sockets.
|
static PortRange |
getTcpInstance()
Returns PortRange instance for TCP listening sockets.
|
static PortRange |
getTcpSourceInstance()
Returns PortRange instance for TCP source sockets.
|
static PortRange |
getUdpSourceInstance()
Returns PortRange instance for UDP source sockets.
|
boolean |
isEnabled()
Checks if the port range is set.
|
boolean |
isInRange(int portNumber)
Checks if the port number if within port range.
|
void |
setUsed(int portNumber)
Sets the port number as used.
|
protected static final byte UNUSED
protected static final byte USED
public static PortRange getInstance()
getTcpInstance()
public static PortRange getTcpInstance()
public static PortRange getTcpSourceInstance()
public static PortRange getUdpSourceInstance()
public boolean isEnabled()
public int getFreePort(int lastPortNumber) throws IOException
lastPortNumber
- port number to start finding the next
available port from. Set it to 0 if
called initialy.IOException
- if there is no more free ports available or
if the lastPortNumber is incorrect.public void setUsed(int portNumber)
portNumber
- port numberpublic void free(int portNumber)
portNumber
- port numberpublic boolean isInRange(int portNumber)
Copyright © 2016. All rights reserved.