我在我的java代码中使用sshxcute-1.0.jar连接到服务器。在服务器上执行某项任务后,程序进入休眠状态(30-40分钟),当它唤醒时,我需要知道程序是否仍然连接到服务器。如果没有,则只重新连接。
//connect to server
cb = new ConnBean(srvDetails.getHost(),srvDetails.getUsrName(),srvDetails.getPwd());
ssh = SSHExec.getInstance(cb);
ssh.connect();
customTask = new ExecCommand("some cmd");
res = ssh.exec(customTask);
// sleep form some time
Thread.sleep(sleepTime);
if(isSrvConnected()){
// Do something..
}else{
//connection to server lost so reconnect
ssh.connect();
}
Boolean isSrvConnected(){
//How to check if app is still connected to server or not...???
}
答案 0 :(得分:0)
Boolean isSrvConnected(){
return ssh.connect();
}