开发者

Detect jsch disconnection

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜