连接到位于路由器后面的 RMI 服务器时出现问题
假设路由器的公共IP是92.1.85.179
服务器计算机的本地IP是192.168.0.2
路由器设置为将 92.1.85.179:5678 转发到 192.168.0.2:5678
在服务器中我有:
System.setProperty( "java.rmi.server.hostname" , "92.1.85.179" );
Registry registry = LocateRegistry.createRegistry( 5678 );
registry.rebind( "TheWebServer" , webServerInt );
客户端有:
Registry registry = LocateRegistry.getRegistry( "92.1.85.179" , 5678 );
server = (WebServerInterface) registry.lookup( "TheWebServer" );
当客户端位于服务器本地网络上时,就可以了。当客户端位于本地网络之外时,它会收到 java.rmi.ConnectException: 连接拒绝主机: 192.168.0.2;
显然,服务器为客户端提供的 IP 为 192.168.0.2,因为它没有出现在代码中,我认为 System.setProperty( "java.rmi.server.hostname" , "92.1.85.179" ); 应该改变。
任何意见将不胜感激。
Let's say the public IP of the router is 92.1.85.179
The local IP of the computer with the server is 192.168.0.2
The router is set to forward 92.1.85.179:5678 to 192.168.0.2:5678
In the server I have:
System.setProperty( "java.rmi.server.hostname" , "92.1.85.179" );
Registry registry = LocateRegistry.createRegistry( 5678 );
registry.rebind( "TheWebServer" , webServerInt );
The client has:
Registry registry = LocateRegistry.getRegistry( "92.1.85.179" , 5678 );
server = (WebServerInterface) registry.lookup( "TheWebServer" );
When client is on the network local to the server it's ok. When the client is outside the local network it gets java.rmi.ConnectException: Connection refused to host: 192.168.0.2;
Obviously the server is giving the client the IP of 192.168.0.2 as it doesn't appear in the code, which I thought System.setProperty( "java.rmi.server.hostname" , "92.1.85.179" );
was supposed to change.
Any input would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您还需要在端口 5678 上导出远程对象,并且需要在导出任何远程对象之前设置 java.rmi.server.hostname。
You need to export your remote objects on port 5678 too, and you need to set java.rmi.server.hostname before you export any remote objects.