code: public static SaneSession withRemoteSane(
        InetAddress saneAddress,
        int port,
        long timeout,
        TimeUnit timeUnit,
        long soTimeout,
        TimeUnit soTimeUnit)
        throws IOException {
      long millis = timeUnit.toMillis(timeout);
      Preconditions.checkArgument(
          millis >= 0 && millis <= Integer.MAX_VALUE,
          "Timeout must be between 0 and Integer.MAX_VALUE milliseconds");
      // If the user specifies a non-zero timeout that rounds to 0 milliseconds,
      // set the timeout to 1 millisecond instead.
      if (timeout > 0 && millis == 0) {
        Logger.getLogger(SaneSession.class.getName())
            .log(
                Level.WARNING,
                "Specified timeout of {0} {1} rounds to 0ms and was clamped to 1ms",
                new Object[] {timeout, timeUnit});
      }
      Socket socket = new Socket();
      socket.setTcpNoDelay(true);
  
      if (soTimeUnit != null && soTimeout > 0) {
        long soTimeoutMillis = soTimeUnit.toMillis(soTimeout);
        Preconditions.checkArgument(
            soTimeoutMillis >= 0 && soTimeoutMillis <= Integer.MAX_VALUE,
            "Socket timeout must be between 0 and Integer.MAX_VALUE milliseconds");
        socket.setSoTimeout((int) soTimeoutMillis);
      }
      socket.connect(new InetSocketAddress(saneAddress, port), (int) millis);
      SaneSession session = new SaneSession(socket);
      session.initSane();
      return session;
    }
docs: Establishes a connection to the SANE daemon running on the given host on the given port. If the
  connection cannot be established within the given timeout,
  {@link java.net.SocketTimeoutException} is thrown.
  
  @param saneAddress
  @param port
  @param timeout Connection timeout
  @param timeUnit Connection timeout unit
  @param soTimeout Socket timeout (for read on socket)
  @param soTimeUnit Socket timeout unit
  @return
  @throws IOException