0

I am trying Remote calls using RMI registry for the first time. I have written the interface and class which implements it. Am facing the problem when am trying to invoke it. I've started rmiregistry in my windows machine by giving start rmiregistry, which opened a new window.

Client side prg looks like:

 String host = "172.27.49.199:1099";
try {
  System.out.println(LocateRegistry.getRegistry());  
  Registry registry = LocateRegistry.getRegistry(host,0);

    Details stub = (Details) registry.lookup("Hello");
    String response = stub.Name();
    System.out.println("response: " + response);
} catch (Exception e) {
    System.err.println("Client exception: " + e.toString());
    e.printStackTrace();
}

I am confused on with what value needs to be given for host.

I've tried giving:

(a) http://localhost (b) http://localhost:1099

It leaves java.net.UnknownHostException: http://localhost:1099.

Update:

After changing host to My_Sys_IP, I lost java.net.UnknownHostException but ending up with Client exception: java.rmi.NotBoundException: Details

Anuj Balan
  • 7,629
  • 23
  • 58
  • 92
  • `NotBoundException` means the item you looked up wasn't there. I suspect you are talking to the wrong Registry: see the comments below my answer. – user207421 Sep 11 '12 at 07:41

1 Answers1

0

I don't know why you're confused. host is a host name or IP address. The Javadoc doesn't say anything about using URLs.

It also doesn't say you can pass zero as a port number. You can't. Omit that parameter if you don't know what it should be.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • Am confused because I've given host as "http://localhost" and even then I get that exception. Changed to Registry registry = LocateRegistry.getRegistry(host); Doesn't work even now – Anuj Balan Sep 11 '12 at 06:13
  • @AnujBalan (1) Does it *really* give `UnknownHostException` for 'localhost'? Hard to believe. (2) What was the value of 'host' in `getRegistry(host)`? (3) Is your server running on 'localhost' as well as the client? Or is it running in another host? In which case that's where the Registry is too, not in the localhost. – user207421 Sep 11 '12 at 07:30
  • (1) I had done an update and not facing unknownhostException. (2)Host = My system IP address (3)Server, client everything resides on the same system. – Anuj Balan Sep 11 '12 at 15:12
  • No, am still ending up with Client exception: java.rmi.NotBoundException: Details. I dnt knw why it happens, because, I am rebinding at server side file with the stub and "Detail" – Anuj Balan Sep 12 '12 at 03:03
  • @AnujBalan So either you are looking at the wrong registry, i.e. in the wrong host, or the bind didn't succeed, or you aren't looking up the same name that you bound. – user207421 Sep 12 '12 at 10:31