0
我是RMI技术的新手,面临以下问题。如何绑定多个RMI服务器的单个对象
我们有多台相同类型的设备连接到本地系统,其中每台设备上的RMI服务都在不同的端口上运行。
当我们试图通过RMI将单个设备连接到本地系统时,它的工作正常。 当我们尝试将第二台设备连接到本地系统时,我们得到以下错误 -
请您帮助我们解决以下问题吗?
在此先感谢。
java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:322)
at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
at java.rmi.Naming.rebind(Naming.java:160)
at com.rmi.server.RMIServer.exportAndBindObject(Unknown Source)
Demo.java
this.myRMIServer = new RMIServer(this.RMIServerPort,this.RMIClientPort, new RMISocketFactory());
this.helloWorld = new HelloWorld();
this.myRMIServer.exportObject(this.helloWorld);
this.myRMIServer.exportAndBindObject(this.rmiServiceName, this.helloWorld);
RMIServer.java
public RMIServer(int port, int rmiPort, java.rmi.server.RMISocketFactory sf)
throws RemoteException {
this.sf = sf;
this.rmiPort = rmiPort;
this.regPort = port;
synchronized (this) {
if (registry == null)
registry = LocateRegistry.createRegistry(port);
}
}
public void exportAndBindObject(String name, RemoteObject ro)
throws RemoteException, MalformedURLException {
exportObject(ro);
String url = "//127.0.0.1:" + this.regPort + "/" + name;
Naming.rebind(url, ro);
}
我看不出您的标题和您的问题之间的任何关系,我无法相信这个代码在任何系统上都可以工作,除非端口相同:请参阅我的答案。 – EJP