i am new with java rmi. And i have a question about rmi usage.
Firstly, i created a server with port(the interface only has a port argument).
this.registry = LocateRegistry.createRegistry(1099);
Then i bind a server like this:
public interface MyRmiService extends Remote {
// return "service name" for example
String getName() throws RemoteException;
}
public void register(MyRmiService service) {
try {
this.registry.rebind(syncDataService.getName(), service);
} catch (RemoteException var3) {
FineLoggerFactory.getLogger().error(var3.getMessage(), var3);
}
}
and my client code is like this:
// linux ip
Registry tempRegistry = LocateRegistry.getRegistry(ip, 1099);
MyRmiService service = (MyRmiService)tempRegistry.lookup("service name");
These code looks fine if my machine ip looks the same with linux shell:
[root@node26 ~]# hostname
node26
[root@node26 ~]# hostname -i
192.168.101.26
[root@node26 ~]# hostname -I
192.168.101.26 192.168.122.1 172.17.0.1
if i use 192.168.101.26 as ip.
But if i get some different ip like this:
# for example
[root@a ~]# hostname -I
172.16.5.199 172.17.0.1
[root@iZbp124z80qrl3rd8pk42xZ ~]# hostname -i
10.162.107.99
[root@iZbp124z80qrl3rd8pk42xZ ~]# hostname
iZbp124z80qrl3rd8pk42xZ
It doesn't work fine and stuck in the client finding service with lookup.
Normally i want to use 172.16.5.199 as ip. But maybe rmi is using 10.162.107.99 which i cannot ping from client. Is this linux server has the right hostname config?
Then I'm confused.
- which hostname or ip is used when
LocateRegistry.createRegistry(1099);called? - which hostname or ip is used when
registry.rebind(syncDataService.getName(), service);called? - which ip should i use to call
LocateRegistry.getRegistry(ip, 1099);? My question is, what exactly the ip should i use?