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

booleanisPortFree(String hostName, String port)
Checks whether the given port is free on the specified host NOTE: works properly only on local host
try {
    return isPortFree(hostName, Integer.parseInt(port));
} catch (Exception e) {
    return false;
booleanisPortFreeClient(String hostName, int portNumber)
is Port Free Client
try {
    if (hostName == null) {
        hostName = getHostName();
    Socket socket = new Socket(hostName, portNumber);
    OutputStream os = socket.getOutputStream();
    InputStream is = socket.getInputStream();
    os.close();
...
BooleanisPortInUse(final String host, final Integer port)
is Port In Use
Boolean result = false;
try {
    (new Socket(host, port)).close();
    result = true;
} catch (IOException ex) {
return result;
booleanisPortInUse(int port)
Checks if the given port is already used
if (port < 0 || port >= 65536) {
    return false;
try (ServerSocket socket = new ServerSocket(port)) {
    return false;
} catch (IOException e) {
    return true;
booleanisPortOnUse(int port)
is Port On Use
boolean isUse = false;
ServerSocket serverSocket = null;
try {
    serverSocket = new ServerSocket(port);
    isUse = false;
} catch (IOException e) {
    e.printStackTrace();
    isUse = true;
...
booleanisPortOpen(int port)
is Port Open
return isPortOpen(new InetSocketAddress("localhost", port));
booleanisPortOpen(int port, String host)
Check whether the provided port is open
Socket socket = null;
boolean isPortOpen;
try {
    socket = new Socket(host, port);
    isPortOpen = socket.isConnected();
} catch (IOException e) {
    isPortOpen = false;
} finally {
...
booleanisPortOpen(String host, int port)
is Port Open
InetSocketAddress socketAddress = new InetSocketAddress(host, port);
Socket socket = null;
try {
    socket = new Socket();
    socket.setReuseAddress(false);
    socket.setSoLinger(false, 1);
    socket.setSoTimeout(TIMEOUT_IN_MILLISECONDS);
    socket.connect(socketAddress, TIMEOUT_IN_MILLISECONDS);
...
booleanisPortUsed(final int portNumber, final String host)
is Port Used
boolean isPortUsed;
ServerSocket serverSocket = null;
try {
    InetAddress inetAddress = InetAddress.getByName(host);
    serverSocket = new ServerSocket(portNumber, 50, inetAddress);
    isPortUsed = false;
} catch (IOException ignored) {
    isPortUsed = true;
...
booleanisPortUsed(int port)
is Port Used
ServerSocket serverSocket = new ServerSocket(port);
return true;