Java Utililty Methods HTTP Port Find

List of utility methods to do HTTP Port Find

Description

The list of methods to do HTTP Port Find are organized into topic(s).

Method

booleanavailable(final int port)
available
ServerSocket serverSocket = null;
try {
    serverSocket = new ServerSocket(port);
    serverSocket.setReuseAddress(true);
    return true;
} catch (final IOException e) {
} finally {
    if (serverSocket != null) {
...
booleanavailable(int port)
Checks to see if a specific port is available(Bind is not called).
ServerSocket ss = null;
DatagramSocket ds = null;
try {
    ss = new ServerSocket(port);
    ss.setReuseAddress(true);
    ds = new DatagramSocket(port);
    ds.setReuseAddress(true);
    return true;
...
booleanavailable(int port)
Checks if a port is available by attempting to create a socket
try {
    Socket ignored = new Socket("localhost", port);
    ignored.close();
    return false;
} catch (IOException ignored) {
    return true;
booleanavailable(int port)
available
Socket s = null;
try {
    s = new Socket("localhost", port);
    return false;
} catch (IOException e) {
    return true;
} finally {
    if (s != null) {
...
booleanavailable(int port)
available
if (port < MIN_PORT_NUMBER || port > MAX_PORT_NUMBER) {
    throw new IllegalArgumentException("Invalid start port: " + port);
ServerSocket ss = null;
DatagramSocket ds = null;
try {
    ss = new ServerSocket(port);
    ss.setReuseAddress(true);
...
intavailable_port()
availablport
return available_port(0);
ServerSocketavailableAndReturn(int MIN_PORT_NUMBER, int MAX_PORT_NUMBER)
available And Return
boolean bindSuccess = false;
ServerSocket ss = null;
AtomicInteger start = new AtomicInteger(MIN_PORT_NUMBER);
while (!bindSuccess && start.get() < MAX_PORT_NUMBER) {
    try {
        ss = new ServerSocket(start.get());
        ss.setReuseAddress(true);
        bindSuccess = true;
...
intavailablePort()
Will determine the available port
ServerSocket s = null;
try {
    s = new ServerSocket(0);
    s.setReuseAddress(true);
    return s.getLocalPort();
} catch (Exception e) {
    throw new IllegalStateException("Failed to discover available port.", e);
} finally {
...
booleanavailablePort(int port)
From: https://stackoverflow.com/questions/434718/sockets-discover-port-availability-using-java
ServerSocket ss = null;
DatagramSocket ds = null;
try {
    ss = new ServerSocket(port);
    ss.setReuseAddress(true);
    ds = new DatagramSocket(port);
    ds.setReuseAddress(true);
    return true;
...
booleanavailablePort(int pPort)
Method that checks whether or not a port is available on the host computer.
ServerSocket newlySocket = null;
boolean response = false;
try {
    newlySocket = new ServerSocket(pPort);
    response = true;
} catch (IOException e) {
    response = false;
} finally {
...