[英]RMI Server to Client call fails when Client machine has more than one IP Address
First off, I'd love to post some real code for this question, but I can't because it's far too many lines. 首先,我想为这个问题发布一些真实的代码,但我不能,因为它太多了。 That said, here's my situation:
那就是说,这是我的情况:
Server Side
服务器端
I have an RMI Server that waits for Clients to connect and "register" themselves, so that the Server can make function calls on Clients. 我有一个RMI服务器等待客户端连接和“注册”自己,以便服务器可以在客户端上进行函数调用。 Basically, the server has a published function that works like the following pseudo-code:
基本上,服务器有一个已发布的函数,其作用类似于以下伪代码:
public class Server extends UnicastRemoteObject implements ServerInterface{
public Server(){ /* Server publishes itself here */ }
...
/** One of many methods visible to a remote Client */
public void registerClient(Client c) throws RemoteException{
//1. Make some remote calls on 'c' for book-keeping purposes
//2. Store reference to c to make calls on it later
}
}
Client Side
客户端
On Startup, the Client makes a call to Naming.lookup([url])
to get a stub to the Server that I'll call serverRef
, then calls serverRef.registerClient(this)
. 在启动时,客户端调用
Naming.lookup([url])
来获取服务器的存根,我将其称为serverRef
,然后调用serverRef.registerClient(this)
。 The problem happens the first line of the server's registerClient(Client c)
method. 问题发生在服务器的
registerClient(Client c)
方法的第一行。
Problem
问题
When the server makes its first remote method call to the Client
inside the registerClient
method, a RemoteException is thrown. 当服务器在
registerClient
方法内对Client
进行第一次远程方法调用时,抛出RemoteException。 While client and server machines are on the same subnet, the client's machine has a secondary IP address. 当客户端和服务器计算机位于同一子网上时,客户端的计算机具有辅助IP地址。 So the IPs look something like this:
所以IP看起来像这样:
Server Machine IPs: 123.45.67.1 服务器机器IP: 123.45.67.1
Client Machine IPs: 123.45.67.2 , 192.168.67.2 客户机IP地址:123.45.67.2,192.168.67.2
The RemoteException that gets thrown during the Server's first remote call back to the client indicates that the Server is trying to connect to the Client's 192.168.67.2 address, which is what's causing the failure. 在服务器的第一次远程回调期间抛出的RemoteException指示服务器正在尝试连接到客户端的192.168.67.2地址,这是导致失败的原因。 The Server should be trying to connect to the 123.45.67.1 address.
服务器应该尝试连接到123.45.67.1地址。 I know that disabling the network interface that belongs to the second IP address would fix the problem, but this isn't really an option for me.
我知道禁用属于第二个IP地址的网络接口可以解决问题,但这对我来说不是一个真正的选择。
Is there any way to "tell" server-side RMI which IP address to connect on when opening a connection to a new client-side object stub? 在打开与新客户端对象存根的连接时,有没有办法“告诉”服务器端RMI连接哪个IP地址?
There are several possible solutions, including 有几种可能的解决方案,包括
write a custom client socket factory 编写自定义客户端套接字工厂
specify addresses in java.rmi.server.hostname property 在java.rmi.server.hostname属性中指定地址
-Djava.rmi.server.hostname=ip_address
etc 等等
Check out this link: 看看这个链接:
These links are also useful: 这些链接也很有用:
java rmi -Djava.rmi.server.hostname=localhost still opens a socket listening on 0.0.0.0 java rmi -Djava.rmi.server.hostname = localhost仍会打开一个监听0.0.0.0的套接字
http://www.chipkillmar.net/2011/06/22/multihomed-hosts-and-java-rmi/4/java-rmi-djava-rmi-server-hostname-localhost-still-opens-a-socket-listening-on http://www.chipkillmar.net/2011/06/22/multihomed-hosts-and-java-rmi/4/java-rmi-djava-rmi-server-hostname-localhost-still-opens-a-socket-听上
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.