开发者

Detect jsch disconnection

开发者 https://www.devze.com 2023-01-17 02:05 出处:网络
How can I detect from the client that jsch session ha开发者_高级运维s been disconnected by the server?You mean other than the isConnected() function on the session object?If you setup a portforwarding

How can I detect from the client that jsch session ha开发者_高级运维s been disconnected by the server?


You mean other than the isConnected() function on the session object?


If you setup a portforwarding with setPortForwardingL() you can use a function like this to verfiy if the tunnel (and the connection) is still alive. (The example tunnels the Echo Service).

public boolean performCheck() throws Exception {
    Socket socket;

    try {
        socket = new Socket("localhost", 7);

        if (socket.isConnected()) {
            socket.close();
            return true;
        }
    } catch (UnknownHostException e) {
        // nothing special
    } catch (IOException e) {
        // nothing special
    }

    return false;
}


Session.isConnected() 

works for me but must be sure you call

Session.setServerAliveInterval(int) 

before

Session.connect()
0

精彩评论

暂无评论...
验证码 换一张
取 消