[英]How check if application is still connected to server using sshxcute
I am using sshxcute-1.0.jar in my java code to connect to server. 我在Java代码中使用sshxcute-1.0.jar连接到服务器。 After performing some task on server, the program goes to sleep (for 30-40 min) and when it wake up i need to know if the program is still connected to the server or not.
在服务器上执行某些任务后,程序进入睡眠状态(持续30-40分钟),当它醒来时,我需要知道程序是否仍连接到服务器。 If not then only reconnect.
如果不是,则仅重新连接。
//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...???
}
Boolean isSrvConnected(){
return ssh.connect();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.