wood burning stoves*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RMI Question" Watch "RMI Question" New topic
Author

RMI Question

Jonathan Pengelly
Greenhorn

Joined: Jan 17, 2004
Posts: 19
Hi all,
I have a question about RMI. Here is the story so far:
I currently create my registy using LocateRegistry.createRegistry(int port). This creates the registry on the local host.
Right. No dramas so far. However, then I use this method to bind my ServicesFactory object into the registry -
registry.rebind("\\host:1099\RemoteServicesFactory", servicesFactoryObject).
If I do this then I can get back my object with the following call in the SAME method -
ServicesFactory s = (ServicesFactory) registry.lookup("\\host:1099\RemoteServicesFactory");
However, when I try to get back my object in another method I use this code and it fails:
registry = LocateRegistry.getRegistry(hostName, portNumber);
servicesFactory = (ServicesFactory) registry.lookup("\\host:1099\RemoteServicesFactory");
It throws an Unknown host exception.
Now, my questions are :
1. Do you guys think it is ok that I only create the registry on the local host? If yes then I guess that I don't need to enter a host name but I will need to know the host name so that I can get the registry in client calls.
2. What is the 'url host name' if the registry gets created on the local host? Should I be using that name when registering the object?
3. Should I be able to run the server on one machine and then get the registered object from another computer on the network (I mean this must be yes for it to be any use but just to make sure)?
Thanks for any comments,
Jonathan
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

Hi Jonathan,
Your local computer is commonly known as "localhost" or "127.0.0.1". Most computers also recognise "localhost.localdomain" and any address in "127.0.0.0/255.255.255.0".
Additionally if your computer is part of a LAN or WAN, you may have a permanent name / IP address assigned to it. If you are using DHCP or getting your IP address through some other dynamic means, you may not be able to use your hostname / IP address.
In the real world, servers are normally assigned a static IP address and their name / IP address are registered in the DNS. So you can then use their name in your calls to the registry.
Do you guys think it is ok that I only create the registry on the local host?

Yes - but I would explicitly use either "localhost" or "127.0.0.1" rather than having it default.
What is the 'url host name' if the registry gets created on the local host?


That is if you want to fully spell out your URL. As you have noted, you can leave out certain parts of it if you want to go with the defaults.
Should I be able to run the server on one machine and then get the registered object from another computer on the network (I mean this must be yes for it to be any use but just to make sure)?

Definately yes.
You should always be able to get the service from a remote machine on a LAN by using the IP address (assuming no firewall is in the way).
Additionally, if the remote machine has it's IP address / hostname registered in a DNS, you should be able to get the service from a remote machine on a LAN by using the hostname.
Additionally, if the remote machine has it's external IP address / hostname registered in a DNS, you should be able to get the service from a remote machine on a WAN by using the hostname / IP address.
Additionally, if the remote machine uses NAT to get an external IP address, you may still be able to get the service from a remote machine on a WAN by using the hostname / IP address, but then you will have to follow Sun's recommendations on working through a firewall. This is far too advanced for this forum though .
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Jonathan Pengelly
Greenhorn

Joined: Jan 17, 2004
Posts: 19
Thanks Andrew. A really clear and well-written answer (as always).
Regards,
Jonathan
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: RMI Question
 
Similar Threads
NX: RMI check available port or host number
I am close to submit - question about rmi
Data class and server code
client - server communication between two machines
Network Mode: Starting Server & Client together