https://community.oracle.com/blogs/emcmanus/2006/12/22/multihomed-computers-and-rmi과이 https://community.oracle.com/thread/1178328?start=0을 읽은 후 다음 솔루션을 사용했습니다. 우리는 모든 응용 프로그램에서 RMIRemoteObjects를 내보내고 한 곳에 모았습니다. 이 솔루션을 사용하면 RMI가 JVM의 한 인스턴스에서 다른 네트워크 인터페이스와 동시에 작동 할 수 있습니다. RmiRemoteManager는 모든 소켓 주소 (네트워크 인터페이스 + 포트)에 대해 생성됩니다. 내보내기 전에 java.rmi.server.hostname
을 정의해야합니다. 이 솔루션은 작동합니다. RMI 제한의 해결 방법임을 기억하십시오.
class ClientSocketFactory implements RMIClientSocketFactory,Serializable{
private InetAddress address;
public ClientSocketFactory(InetAddress address)
{
this.address = address;
}
@Override
public Socket createSocket(String host, int port) throws IOException {
Socket socket =new Socket(address, port);
return socket;
}
@Override
public boolean equals(Object that)
{
return that != null && this.getClass() == that.getClass();
}
}
class ServerSocketFactory implements RMIServerSocketFactory{
private InetAddress address;
public ServerSocketFactory(InetAddress address)
{
this.address = address;
}
@Override
public ServerSocket createServerSocket(int port) throws IOException{
return new ServerSocket(port, 0, address);
}
@Override
public boolean equals(Object that)
{
return that != null && this.getClass() == that.getClass();
}
}
public class RmiRemoteManager {
private Registry registry;
private InetSocketAddress socketAddress;
private ServerSocketFactory serverSocketFactory;
private ClientSocketFactory clientSocketFactory;
public RmiRemoteManager(InetSocketAddress socketAddress) {
try {
this.socketAddress = socketAddress;
serverSocketFactory=new ServerSocketFactory(InetAddress.getByName(socketAddress.getHostName()));
clientSocketFactory=new ClientSocketFactory(InetAddress.getByName(socketAddress.getHostName()));
//the registry is exported via createRegistry.
registry = LocateRegistry.createRegistry(this.socketAddress.getPort(),clientSocketFactory,serverSocketFactory);
} catch (UnknownHostException ex) {
Logger.getLogger(RmiRemoteManager.class.getName()).log(Level.SEVERE, null, ex);
} catch (RemoteException ex) {
Logger.getLogger(RmiRemoteManager.class.getName()).log(Level.SEVERE, null, ex);
}
}
private synchronized static Remote export(Remote remoteObject,InetSocketAddress sa,ClientSocketFactory csf,ServerSocketFactory ssf){
try {
System.setProperty("java.rmi.server.hostname",sa.getHostName());
return UnicastRemoteObject.exportObject(remoteObject,sa.getPort(),csf,ssf);
} catch (RemoteException ex) {
Logger.getLogger(RmiRemoteManager.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
public void export(Remote remoteObject,String url){
try {
Remote stub=export(remoteObject,socketAddress,clientSocketFactory,serverSocketFactory);
remoteObjects.add(remoteObject);
if (url!=null){
urlsByRemoteObjects.put(remoteObject, url);
registry.rebind(url, stub);
}
} catch (RemoteException ex) {
Logger.getLogger(RmiRemoteManager.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
나는 포트가 내가 당신을 이해하지 못하는 cricket_007 @ 네트워크 인터페이스 –
보다 문제가 더 생각 - 내가 RMI 작업 포트 아무 문제가 없다. 문제는 다른 네트워크 인터페이스를 사용하는 것입니다. –
어쩌면 내가 오해했을 것입니다. 두 네트워크 인터페이스 모두 동일한 호스트 이름과 문제를 해결합니까? –