Java Ganymed ssh 隧道...如何检查隧道是否仍然打开?

发布于 2024-09-15 14:50:21 字数 536 浏览 4 评论 0原文

我有一个使用 Ganymed 的 LocalPortForwarder 类创建的 ssh 隧道。运行良好。问题是如何(以 Java 编程方式)检查隧道是否仍然打开且处于活动状态?

作为参考,这里是创建隧道的代码片段(为简洁起见,删除了错误检查):

Connection conn = new Connection(remoteHostName);

conn.connect();

boolean isAuthenticated = conn.authenticateWithPassword(username, password);

LocalPortForwarder lpf1
               = conn.createLocalPortForwarder(newPort,
                                               remoteHostName, 
                                               Integer.parseInt(remoteHostPort));

I have an ssh tunnel created with Ganymed's LocalPortForwarder class. It's working fine. The question is how (programmatically in Java) do I check that the tunnel is still open and active?

For reference, here's the code snippet that creates the tunnel (error checking removed for brevity's sake):

Connection conn = new Connection(remoteHostName);

conn.connect();

boolean isAuthenticated = conn.authenticateWithPassword(username, password);

LocalPortForwarder lpf1
               = conn.createLocalPortForwarder(newPort,
                                               remoteHostName, 
                                               Integer.parseInt(remoteHostPort));

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╭ゆ眷念 2024-09-22 14:50:21

检测任何 TCP 连接状态的唯一方法是尝试使用它。它不像 SNA 过去那样有“心跳”。

The only way to detect the state of any TCP connection is to try to use it. It doesn't have a 'heartbeat' like SNA used to.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文