Click to See Complete Forum and Search --> : RMI problem
maverick13
March 23rd, 2007, 04:13 AM
Hi,
I am using rmi's in my program and i met with the following error::
Whenever i do the remote method invocation,the client rather than looking up or searching at the server whose IP address
is specified,ends up searching at loopback(i.e at IP address 127.0.0.1).when the command say
comp = (RemoteCommand)Naming.lookup(***)
is invoked...
I tried printing out the contents of the variable "comp" here and it is as follows::
Proxy[RemoteCommand,RemoteObjectInvocationHandler[UnicastRef [liveRef: [endpoint:[127.0.0.1:45832]..
I tried executing the client side with the following explicit declaration of the server IP address::
java -Djava.security.policy=server.policy -Djava.rmi.server.hostname=172.23.1.145 Engine
But still i faced the same problem..
However,when both the client and server are executed on the same system,the program works fine..
keang
March 24th, 2007, 12:33 PM
Where is the rmiregistry running and how are you binding the remote objects to the rmiregistry?
Can you show some code.
maverick13
March 26th, 2007, 06:13 PM
I create the registry on both client and server...
This is the server side code:
String name = new String("Compute");
RemoteCommand server = new ExecServer();
RemoteCommandstub=(RemoteCommand)UnicastRemoteObject.exportObject(server, 0);
Registry registry = LocateRegistry.getRegistry();
System.out.println("Done!");
System.out.println("\nTrying to bind....");
registry.bind(name, stub);
On the client i invoked this command as told above::
String name = new String ("Compute");
Registry registry = LocateRegistry.getRegistry(//tried with ip here also);
System.out.println(registry);
String names[] = registry.list();
for(int i = 0; i< names.length; i++)
System.out.println(names[i]);
comp = (RemoteCommand)Naming.lookup("rmi://172.23.1.145:1099/name");
I tried printing out the contents of the variable "comp" here and it is as follows::
Proxy[RemoteCommand,RemoteObjectInvocationHandler[UnicastRef [liveRef: [endpoint:[127.0.0.1:45832]..
However the contents of registry (accessed by registry.list above) are printed out properly..Its only during lookup that it ends looking up at the localhost...
keang
March 27th, 2007, 07:09 AM
I create the registry on both client and server...You are not creating a registry at all. You are getting a local reference to a remote bootstrap registry that may or may not exist. To create a registry (as opposed to running rmiregistry directly) you need to call createRegistry(..).
I have limited experience of using rmi so the following advice may not be optimal but I have got it working across networks as follows:
Create a registry on the server and bind your remote objects to it as follows:LocateRegistry.createRegistry(port); // registries normally run on port 1099
Naming.bind(hostname+LOOKUPNAME, myRemoteObject);Then on your client you just need to look up the name as follows:myRemoteObject = (MyRemoteObjectType)Naming.lookup(hostName+LOOKUPNAME);
comp = (RemoteCommand)Naming.lookup("rmi://172.23.1.145:1099/name");You don't need to start the hostname with "rmi:" and the bit after the final '/' must be the same name as you used to bind the remote object eg "Compute" and not "name" or was this supposed to be:for(int i = 0; i< names.length; i++)
{
System.out.println(names[i]);
comp = (RemoteCommand)Naming.lookup("rmi://172.23.1.145:1099/"+name[i]);
}
maverick13
March 27th, 2007, 09:40 PM
Tis is the full code on the server side...
System.setProperty("java.security.policy", "server.policy");
if (System.getSecurityManager() == null)
{
System.setSecurityManager(new SecurityManager());
}
try
{
java.rmi.registry.LocateRegistry.createRegistry(1099); System.out.println("RMI registry ready.");
}
catch (Exception e)
{
System.out.println("Exception starting RMI registry\n" + e);
return;
}
Tis is the full code on the clientr side...
if (System.getSecurityManager() == null)
{
System.setSecurityManager(new SecurityManager());
}
try
{
java.rmi.registry.LocateRegistry.createRegistry(1099);
System.out.println("RMI registry ready.");
}
catch (Exception e)
{
System.out.println("Exception starting RMI registry\n" + e);
}
As you can see i have created the registry on both sides...Even tried with only creating it at the server side but still had no success..
As for "name" in the previous post,name contains the lookup name i.e compute..see the first line here...
String name = new String ("Compute");
Registry registry = LocateRegistry.getRegistry();
System.out.println(registry);
String names[] = registry.list();
for(int i = 0; i< names.length; i++)
System.out.println(names[i]);
comp = (RemoteCommand)Naming.lookup(name);
System.out.println("comp\n" + comp);
keang
March 28th, 2007, 07:07 AM
You haven't mentioned any SecurityExceptions so I am assuming your security policy is granting all the correct permissions.
Please use code tags when posting code.
Tis is the full code on the server side...So where are you binding the remote object to the registry? Are you appending the hostname (without the "rmi:" part) to the lookup name (see my example)?
Tis is the full code on the clientr side..Do not create registries on both the client and server, you just need one running on the server.
Where is the Naming.lookup line? and are you looking up the correct name eg the host name (without the "rmi:" part) + the lookup name.
As for "name" in the previous post,name contains the lookup nameThe line I was refering to had the text 'name' inside the quoted lookup string, it was not appending the string in the variable 'name' which is what it ought to be doing. Given that you were getting a list of all available names I assumed you wanted to get all available objects hence I included the lookup in the for loop.
keang
April 8th, 2007, 06:49 AM
Hi maverick13,
Have you solved this problem yet?
I came across the following statement in an RMI tutorial which may be part of your problem with remote deployment not working:
"Be careful to start the RMI registry in its own directory, away from where you are
storing (or building!) the RMI stubs. If RMI can find the stubs in its own CLASSPATH,
it will assume they are universally available and won’t download them!"
codeguru.com
Copyright WebMediaBrands Inc., All Rights Reserved.