Is it possible to create a registry only on a specific loopback address in Java RMI?

339 views Asked by At

I'm working with Java RMI. Client and server are on the same machine yet. To start the registry on the server, I'm currently using

int serverPort = 8081;          
Registry registry = LocateRegistry.createRegistry(serverPort); 

So my registry is started on the IP of my machine and the specified port. The client gets the registry with this code

Registry registry = LocateRegistry.getRegistry(127.0.0.1, 8081);

but also when I use one of the other loopback addresses like 127.0.0.2, 127.0.0.3 .. 127.255.255.254. Is there a possibility that I can spefified the ip for only one loopback address (e. g. only for 127.0.0.1) when creating the registry? There is no method like:

LocateRegistry.createRegistry(ip, port); 
1

There are 1 answers

0
user207421 On

So my registry is started on the IP of my machine and the specified port.

No it isn't. It is created as listening to 0.0.0.0 and the specified port.

If you want the listening socket to listen at a specific IP address you have to supply an RMIServerSocketFactory that creates ServerSockets that do that.