user2964628
user2964628

Reputation: 51

JSCH session connection issue

I ran the below program and reboot the host which takes almost 6 to 8 mins to complete the reboot, but i never get the timed out.. i.e is it never go to else part.

    public static void main(String a[]) throws JSchException, InterruptedException {
        java.util.Properties config = new java.util.Properties();
        JSch jsch = new JSch();
        String user = "cli";
        String host = "135.104.217.114";
        String password = "cli";
        int port = 22;
        Session session = jsch.getSession(user,host,port);
        config.put("StrictHostKeyChecking", "no");
        session.setConfig(config);
        session.setPassword(password);
        session.connect();
        while(true)
        {
            if(session.isConnected())
            {
                System.out.println("session connected");
            }
            else
            {
                System.out.println("sesion not connected--------------");
            }
            Thread.sleep(1000);
        }
    }

Upvotes: 1

Views: 2240

Answers (1)

aglassman
aglassman

Reputation: 2653

You most likely need to configure the "Sever Alive" properties.

session.setServerAliveInterval(5000); // Check if server is alive every 5 seconds
session.setServerAliveCountMax(5);  // Disconnect after 5 Server Alive checks did not receive a response.

Upvotes: 1

Related Questions