【发布时间】:2012-01-14 11:17:43
【问题描述】:
我有一个使用 RMI 进行客户端/服务器通信的 Java 应用程序。 为确保此通信的安全,流量通过 ssh 连接进行隧道传输。
一切正常,除了连接在几秒钟后自动关闭。
我已将 keep alive 属性设置为 true:
- SSHD 连接
- SSH 客户端连接
- ServerSocket 服务器端
- ClientSocket 客户端
连接到寄存器(端口 4000)并在对象(端口 4005)上调用方法的常见连接例程输出以下日志:
INFO org.apache.sshd.server.session.ServerSession - Authentication succeeded
INFO org.apache.sshd.server.session.ServerSession - Received SSH_MSG_CHANNEL_OPEN direct-tcpip
INFO org.apache.sshd.server.channel.ChannelDirectTcpip - Receiving request for direct tcpip: hostToConnect=ThinkPad, portToConnect=4000, originatorIpAddress=127.0.0.1, originatorPort=64539
INFO org.apache.sshd.server.session.ServerSession - Received SSH_MSG_CHANNEL_OPEN direct-tcpip
INFO org.apache.sshd.server.channel.ChannelDirectTcpip - Receiving request for direct tcpip: hostToConnect=ThinkPad, portToConnect=4005, originatorIpAddress=127.0.0.1, originatorPort=64540
INFO org.apache.sshd.server.channel.ChannelDirectTcpip - Received SSH_MSG_CHANNEL_EOF on channel 1
INFO org.apache.sshd.server.channel.ChannelDirectTcpip - Send SSH_MSG_CHANNEL_CLOSE on channel 1
INFO org.apache.sshd.server.channel.ChannelDirectTcpip - Received SSH_MSG_CHANNEL_CLOSE on channel 1
INFO org.apache.sshd.server.channel.ChannelDirectTcpip - Closing channel 1 immediately
INFO org.apache.sshd.server.channel.ChannelDirectTcpip - Closing channel 1 immediately
INFO org.apache.sshd.server.channel.ChannelDirectTcpip - Send SSH_MSG_CHANNEL_EOF on channel 1
INFO org.apache.sshd.server.session.ServerSession - Closing session
INFO org.apache.sshd.server.channel.ChannelDirectTcpip - Closing channel 0 immediately
INFO org.apache.sshd.server.channel.ChannelDirectTcpip - Closing channel 0 immediately
INFO org.apache.sshd.server.channel.ChannelDirectTcpip - Send SSH_MSG_CHANNEL_EOF on channel 0
** Received SSH_MSG_CHANNEL_EOF on channel 1 ** 表明在对象上调用的方法已生成 EOF 消息。这会导致会话关闭...
我能想到的可能解决方案:
- 拦截或阻止 EOF 消息(但在哪里以及如何?)
- 尝试配置服务器端sessionfactory忽略EOF消息(感觉不对……)
【问题讨论】:
-
根据this site EOF 不应导致此连接结束。
-
但也按照那个站点 SSH_MSG_CHANNEL_CLOSE 当然应该关闭它,并且它正在被发送。
-
看起来服务器收到 EOF 消息并以 CLOSE 消息响应,然后服务器自己发送 EOF。我想知道在客户端关闭通道后是否也会发送第一个收到的 EOF 以及如何防止这种情况。
标签: java ssh connection rmi keep-alive