RMI: take ip/hostname what client was using and give it back as aremote objects hostname



RMI: take ip/hostname what client was using and give it back as a remote
objects hostname. Long question but here is what I try to ask.

Currently I use the following code to start RMIRegistry inside my
application and bind Remote objects. I can bind several objects to the
same port. Actually, I run a rmi registry lookup and remote object
"handles" in a same fixed port. Its more NAT-firewall friendly.

When clients lookup a remote object handle from the registry, they
receive a hostname where given service is running. It is a server that
tells them to use that hostname. This is a small problem in a
NAT-firewall world.

I must use "-Djava.rmi.server.hostname=myPublicHostName.com" commandline
parameter to override internal hostname seen by the server machine. It
would give internal DMZ ip address if not overriden this way.

Best method would use the same hostname what client was using the first
place when connected to RMI registry to look for remote handles. It is
after all an address it can use when connecting to our server.

Is it possible to take that ip/hostname and give it back along with the
remoteobject's hostname?

- - - -
Registry reg;

public void createReg(int port) throws Exception {
try {
reg = LocateRegistry.createRegistry(port); // registry port number
} catch (Exception ex) {
// probably was already running so take existing registry instance.
reg = LocateRegistry.getRegistry(port);

public void bindService(String id, int port) thows Exception {
Remote obj = createMyRemoteImplementationXX();
UnicastRemoteObject.exportObject(obj, port);
reg.rebind(id, obj);
- - - -


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question