wood burning stoves 2.0*
The moose likes Distributed Java and the fly likes RMI binding to more than one IP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "RMI binding to more than one IP" Watch "RMI binding to more than one IP" New topic
Author

RMI binding to more than one IP

Raman Naresh
Greenhorn

Joined: Nov 27, 2008
Posts: 3
Hi , in my application where the clients communicate with the server through RMI, the exported remote objects are bound to the hostname set in "java.rmi.server.hostname" system property.

If the server has two NIC cards, then is it possible for the clients on different networks to connect to the server with the Network IP address to which it belongs other than the default one (obtained from system property) (ie) is it possible for the RMI server to listen for requests coming on both the IP adresses. Will the Custom RMI Socket factory helps in this.
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Won't binding the server at 0.0.0.0 and removing java.rmi.server.hostname system property do it for you?
This would mean that the server listens to all interfaces and the client can use any interface.

Or is it so that you want to restrict the clients only to a certain set of Interfaces?


apigee, a better way to API!
Raman Naresh
Greenhorn

Joined: Nov 27, 2008
Posts: 3
Hi,

Thanks for the response. Please let me know how to bind it to 0.0.0.0 as CreateRegistry and bind methods do not have arguments to take ipaddress.
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

If you do not specify any host using RMIServerSocketFactory, it will bind to 0.0.0.0.

(Sorry, i should have commented on this before)
Raman: the exported remote objects are bound to the hostname set in "java.rmi.server.hostname" system property


Nope, actually, this property is for the hostname the clients will connect on.
So, the server is exported on the hostname(interface) that is specified by the server socket factory and clients connect to interface specified by "java.rmi.server.hostname" system property, if any.
This bug has more details.

So, in your code, i guess you just need to remove "java.rmi.server.hostname" system property and things should fall in place.
[ December 01, 2008: Message edited by: Nitesh Kant ]
Raman Naresh
Greenhorn

Joined: Nov 27, 2008
Posts: 3
Hi, can you please know me the diference between RMIServerSocketFactory and RMIClientSocketFactory. As far as my understand when we use RMIClientSocketFactory while exporting the object , RMI creates the socket from client to server by takeing the ipaddress that is supplied as an argument to RMIClientSocketFactory Impl constructor instead of using InetAddress.getLocalHost.getAddress().

In this way , I can get rid of the localhost server address and use the ipaddress which the client can communicate. This works for the one client, but with multiple clients , im not able to export the same object with differnt ipaddress as it says objectID already in use. IN our network we have two clients , one from 10.10.10.x and other from 20.20.20.x . The server has one internal ipaddress 192.168.2.2 and two additional NIC cards , one is 10.10.10.1 and the other 20.20.20.1, in this way the two client cannot communicate with each other and RMI should be enabled on all the three ipaddress, ie client from 10.10.10.x should communicate with server thru 10.10.10.1 and client from 20.20.20.x should communicate with server thru 20.20.20.1

I also tried with creating the registry with RMIServerSocketFactory with no argument. But its not working. Could you please provide me an example.
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Raman: IN our network we have two clients , one from 10.10.10.x and other from 20.20.20.x . The server has one internal ipaddress 192.168.2.2 and two additional NIC cards , one is 10.10.10.1 and the other 20.20.20.1, in this way the two client cannot communicate with each other and RMI should be enabled on all the three ipaddress, ie client from 10.10.10.x should communicate with server thru 10.10.10.1 and client from 20.20.20.x should communicate with server thru 20.20.20.1


Can't you have a single interface for the RMI stub? Why is it required that the client from 10.10.10.x should have a different IP address in the RMI stub too.
I think there are two things:
  • Interface at which the rmi registry is running.
  • Interface at which the client stub is connecting.


  • If by saying "rmi is enabled" means the registry is available then you would have to have a routing rule i guess that will route all traffic from one interface on the registry port to another or a common interface to which the data is routed to from both 10.10.10.x and 20.20.20.x.
    (I must say that I am not a networking expert but this is what i can think of)

    If you are saying the client stub must contain different interfaces according to the interface on which it is invoked, then this is difficult if not impossible.
    What is it that you loose if your client stub always connects on one IP address and registry is available on both?
    I am sure nobody cares what interface the client stub is connecting too as long as the interface is a publicly available IP.
    [ December 04, 2008: Message edited by: Nitesh Kant ]
     
    wood burning stoves
     
    subject: RMI binding to more than one IP