2011-12-06 42 views
0

我有一個使用RMI進行客戶端/服務器通信的Java應用程序。 爲了確保這種通信的安全,流量通過ssh連接進行隧道傳輸。阻止Java RMI套接字連接上的EOF消息

一切正常,除非連接在幾秒鐘後自動關閉。

我已經設置了永葆財產的真實:

  • SSHD連接
  • SSH客戶端連接
  • ServerSocket的服務器端
  • ClientSocket的客戶端

常見的連接步驟連接到寄存器(端口4000)並調用對象上的方法(端口4005)輸出foll虧欠的日誌:

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 

線**收到SSH_MSG_CHANNEL_EOF通道1 **表明調用的對象上的方法已經生成一個EOF消息。然後,這將導致我能想到的尾盤收...

可能的解決方案:

  • 攔截或防止EOF消息(但在哪裏以及如何?)
  • 嘗試配置服務器端的SessionFactory忽略EOF消息(感覺不對...)
+0

根據[本網站](http://www.networkdictionary.com/rfc/rfc4254.php?page=0%2C2)* EOF *不應導致此連接結束。 – srkavin

+0

但也根據該站點SSH_MSG_CHANNEL_CLOSE肯定應該關閉它,並且它正在發送。 – EJP

+0

它看起來像服務器收到EOF消息,並用CLOSE消息作出響應,然後服務器自己發送一個EOF。我想知道在客戶端關閉通道後是否也發送了第一個收到的EOF,以及如何防止這種情況發生。 –

回答

0

RMI連接在客戶端池化,如果在15秒內不重用,則關閉。您可以通過系統屬性調整此行爲:請參閱從RMI主頁鏈接的Sun系統屬性頁面。

+0

謝謝EJP的黃金提示。這個問題可以通過一個oneliner來解決(在客戶端): System.setProperty(「sun.rmi.transport.connectionTimeout」,「3600000」); –