Hello??There's a question I'd like to ask about apache-sshd keealive.

The sshclient only send keepAlive every interal time,but not to check the reply 
of the keepAlive timeout.
> how does the client know that the server is available.
> Or does other param need to set to make the client heartbeat work?



what param of ssh client I set is :
I just set the HEARTBEAT_INTERVAL(20 senconds) and the 
IDLE_TIMEOUT(300senconds), the NIO_READ_TIMEOUT(315seconds).Does other param 
need to set to make the heartbeat available?


related code i understand is: 
 protected void startHeartBeat() {
        ClientSession session = getClientSession();
        long interval = 
session.getLongProperty(ClientFactoryManager.HEARTBEAT_INTERVAL, 
ClientFactoryManager.DEFAULT_HEARTBEAT_INTERVAL);
        if (interval > 0L) {
            FactoryManager manager = session.getFactoryManager();
            ScheduledExecutorService service = 
manager.getScheduledExecutorService();
            service.scheduleAtFixedRate(this::sendHeartBeat, interval, 
interval, TimeUnit.MILLISECONDS);
            if (log.isDebugEnabled()) {
                log.debug("startHeartbeat - started at interval={}", interval);
            }
        }
    }
 
    /**
     * Sends a heartbeat message
     * @return The {@link IoWriteFuture} that can be used to wait for the
     * message write completion
     */
    protected IoWriteFuture sendHeartBeat() {
        ClientSession session = getClientSession();
        String request = 
session.getStringProperty(ClientFactoryManager.HEARTBEAT_REQUEST, 
ClientFactoryManager.DEFAULT_KEEP_ALIVE_HEARTBEAT_STRING);
        try {
            Buffer buf = 
session.createBuffer(SshConstants.SSH_MSG_GLOBAL_REQUEST, request.length() + 
Byte.SIZE);
            buf.putString(request);
            buf.putBoolean(false);
            return session.writePacket(buf);
        } catch (IOException e) {
            if (log.isDebugEnabled()) {
                log.debug("Error (" + e.getClass().getSimpleName() + ") sending 
keepalive message=" + request + ": " + e.getMessage());
            }
 
            Throwable t = e;
            return new AbstractIoWriteFuture(request, null) {
                {
                    setValue(t);
                }
            };
        }
    }

Reply via email to