私は RMI テクノロジに不慣れで、以下の問題に直面しています。
ローカル システムに接続された同じタイプの複数のデバイスがあり、各デバイスで RMI サービスが異なるポートで実行されています。
RMI を介して単一のデバイスをローカル システムに接続しようとすると、正常に動作します。2 番目のデバイスをローカル システムに接続しようとすると、次のようなエラーが発生します -
以下の問題の解決にご協力いただけますでしょうか。
前もって感謝します。
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)
デモ.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);
}