code: public static boolean isSocketAlive(final SocketAddress socketAddress, final int timeoutMsecs) {
          final Socket socket = new Socket();
          try {
              socket.connect(socketAddress, timeoutMsecs);
              socket.close();
              return true;
          } catch (final SocketTimeoutException exception) {
              return false;
          } catch (final IOException exception) {
              return false;
          }
      }
docs: Returns true if a connection can be established to the given socket address within the
  timeout provided.
  
  @param socketAddress
  socket address
  @param timeoutMsecs
  timeout
  @return true if a connection can be established to the given socket address