The Naming class's methods take, as one of their arguments, a name that is a URL formatted java.lang.String of the form: //host ort/name where host is the host (remote or local) where the registry is located, port is the port number on which the registry accepts calls, and where name is a simple string uninterpreted by the registry. Both host and port are optional. If host is omitted, the host defaults to the local host. If port is omitted, then the port defaults to 1099, the "well-known" port that RMI's registry, rmiregistry, uses. Binding a name for a remote object is associating or registering a name for a remote object that can be used at a later time to look up that remote object. A remote object can be associated with a name using the Naming class's bind or rebind methods.
I have a question here: Considering the default port 1099: 1. If the lookup is in localhost, then the url would be:
But can someone explain what should be in the url for remotehost is it the ip address?
That would be an IP address or simply the name of the server, such as "fatBrain", "deepBlue", etc. To see what your computer name is on Windows, right click My Computer|Properties|Network Identification (this may be different on Windows 95/98/2000/NT/XP) Eugene.
Joined: Apr 27, 2001
Originally posted by Eugene Kononov:
That would be an IP address or simply the name of the server, such as "fatBrain", "deepBlue", etc. Eugene.
Thanks Eugene! If host is just the name of the server, which is bound to registry, then can you please explain what is Name here:
So, does this mean that the following code is correct:
FactoryInterface fi =(FactoryInterface)Naming.lookup("rmi://serverName");
where serverName is an instance of ServerFactoryImplementation class, bound to registry like this:
Naming.rebind(serverName, new FactoryImpl());
Joined: Oct 08, 2001
If host is just the name of the server, which is bound to registry, then can you please explain what is Name here:
No, the host is the name of the physical server, i.e, the name of the computer. As I recommended, look up the name of your computer so that you are not confused. What you bind to the registry is the remote object. For some reson, many people are confused with the concept of registry and binding to it. It couldn't be simpler, -- loosely speaking, the registry is just a block of memory where you make your objects available for everyone to see. The registry is organized as a map, where your key is the name of you object (any String, such as "my object"), and and the value is the actual object. Thus, to bind an object to registry, all you need to do is: registry.bind("my object", myObject); Notice that you don't need to specify the machine name or port, because the object is bound on this machine. Now, to retreve the object from another machine, you must specify the machine name (such as "fatBrain", or 22.214.171.124), the port (such as 1099), and the name to which the object is mapped ("my object"): String service = "//" + "fatBrain" + ":" + 1099 + "/" + "my object"; myObject = (MyObjectInterface) Naming.lookup(service); That's all there is to it, -- one line of code for bind(), two lines for lookup(). The client needs to know the server name to connect, of course. Eugene. [ April 01, 2003: Message edited by: Eugene Kononov ]
Joined: Apr 27, 2001
Thanks Eugene, for that wonderful explanation! Now, if i have just Naming.lookup("rmi://"+remoteObject); 1. if i don't mention any hostname/ipaddress 2. and if its only the default port, 3. and i have the remote object bind to registry, then Naming.lookup will search in rmi://localhost, right? If this is right, then in my code, i get classcast exception, why? Can you please see my other post too, even Mark is trying to help me out. thanks, sri