English 中文(简体)
Detect jsch disconnection
原标题:

How can I detect from the client that jsch session has 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()




相关问题
How can I detect if the user is on localhost in PHP?

In other words, how can I tell if the person using my web application is on the server it resides on? If I remember correctly, PHPMyAdmin does something like this for security reasons.

Tracking Right click menu events?

Is there a way to track the right click menu when clicked over a textarea. I would like to know if the user selected cut,copy,paste,select all. Also, I can know when the menu is visible by detecting ...

Recovering from stack overflow on Mac OS X

I am implementing a cross platform scripting language for our product. There is a requirement to detect and properly handle stack overflow condition in language VM. Before you jump in and say make ...

Detecting login credentials abuse

I am the webmaster for a small, growing industrial association. Soon, I will have to implement a restricted, members-only section for the website. The problem is that our organization membership both ...

How to detect page zoom level in all modern browsers?

How can I detect the page zoom level in all modern browsers? While this thread tells how to do it in IE7 and IE8, I can t find a good cross-browser solution. Firefox stores the page zoom level for ...

热门标签