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

booleanisPortAvailable(int port)
Check if port is available
ServerSocket serverSocket;
try {
    serverSocket = new ServerSocket();
} catch (IOException ex) {
    throw new IllegalStateException("Unable to create ServerSocket.", ex);
try {
    InetSocketAddress sa = new InetSocketAddress(port);
...
booleanisPortAvailable(int port)
See if a port is available for listening on by trying to listen on it and seeing if that works or fails.
try {
    ServerSocket socket = new ServerSocket(port);
    socket.close();
    return true;
} catch (IOException e) {
    return false;
booleanisPortAvailable(int port)
is Port Available
ServerSocket ss = null;
DatagramSocket ds = null;
try {
    ss = new ServerSocket(port);
    ss.setReuseAddress(true);
    ds = new DatagramSocket(port);
    ds.setReuseAddress(true);
    return true;
...
booleanisPortAvailable(int port)
is Port Available
try (DatagramSocket udp = new DatagramSocket(port); ServerSocket tcp = new ServerSocket(port)) {
    tcp.setReuseAddress(true);
    udp.setReuseAddress(true);
    return true;
} catch (IOException ex) {
    return false;
booleanisPortAvailable(int port)
Checks to see if a specific port is 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);
...
booleanisPortAvailable(int port)
is Port Available
if (port < 1 || port > 65535) {
    throw new IllegalArgumentException("Invalid start port: " + port);
try (ServerSocket ss = new ServerSocket(port); DatagramSocket ds = new DatagramSocket(port)) {
    ss.setReuseAddress(true);
    ds.setReuseAddress(true);
    return true;
} catch (IOException ignored) {
...
booleanisPortAvailable(int port)
Checks to see if a specific port is available.
ServerSocket ss = null;
DatagramSocket ds = null;
try {
    ss = new ServerSocket(port);
    ss.setReuseAddress(true);
    ds = new DatagramSocket(port);
    ds.setReuseAddress(true);
    return true;
...
voidisPortAvailable(String host, int port)
is Port Available
Socket s = new Socket();
s.bind(new InetSocketAddress(host, port));
s.close();
booleanisPortAvailable(String host, int port)
See if a port is available for listening on by trying connect to it and seeing if that works or fails
try {
    Socket socket = new Socket(host, port);
    socket.close();
    return false;
} catch (IOException e) {
    return true;
booleanisPortAvailable(String host, int port)
is Port Available
Socket socket = null;
boolean available = false;
try {
    socket = new Socket(host, port);
    available = true;
} catch (IOException e) {
} finally {
    if (socket != null) {
...