Java Utililty Methods Socket Check

List of utility methods to do Socket Check

Description

The list of methods to do Socket Check are organized into topic(s).

Method

booleanisConnected(Socket socket)
is Connected
return socket != null && socket.isBound() && !socket.isClosed() && socket.isConnected()
        && !socket.isInputShutdown() && !socket.isOutputShutdown();
booleanisSocketClosed(SocketException e)
is Socket Closed
return e.getMessage().equals("Socket closed");
booleanisSocketReadyToWrite(Socket socket)
Determines if the socket can be written to.
OutputStream out = socket.getOutputStream();
try {
    out.write(0);
    out.flush();
    out.write(0);
    out.flush();
} catch (SocketException e) {
    return false;
...
booleanisSocketTimeoutException(final InterruptedIOException e)
If SocketTimeoutExceptionClass is defined, returns true only if the exception is an instance of SocketTimeoutExceptionClass.
return e instanceof SocketTimeoutException;