防止Java RMI套接字连接上的EOF消息

时间:2011-12-06 21:15:58

标签: java ssh connection rmi keep-alive

我有一个使用RMI进行客户端/服务器通信的Java应用程序。 为了保护这种通信,流量通过ssh连接进行隧道传输。

除了连接几秒钟后连接自动关闭外,一切运行良好。

我将keep alive属性设置为:

  • 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

在通道1 **上接收到SSH_MSG_CHANNEL_EOF的行**表明在对象上调用的方法已生成EOF消息。这会导致会话结束......

我能想到的可能的解决方案:

  • 拦截或阻止EOF消息(但在哪里以及如何?)
  • 尝试配置服务器端sessionfactory以忽略EOF消息(感觉不对......)

1 个答案:

答案 0 :(得分:0)

RMI连接汇集在客户端,如果不在15秒内重用,则关闭。您可以通过系统属性调整此行为:请参阅从RMI主页链接的Sun系统属性页。