• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

RMI Question

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Jonathan Pengelly
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Andrew. A really clear and well-written answer (as always).
Regards,
Jonathan
reply
    Bookmark Topic Watch Topic
  • New Topic