File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Problem running Naming.rebind in RMI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Problem running Naming.rebind in RMI" Watch "Problem running Naming.rebind in RMI" New topic
Author

Problem running Naming.rebind in RMI

Mark O' Sullivan
Ranch Hand

Joined: Aug 17, 2009
Posts: 160
Hi,
I'm having problems running a demo class to test my network connectivity with RMI. The start of the main method is like this.

Getting error like this.
"Exception in thread "main" java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection refused: connect"
Main error from stack trace:
"at sun.rmi.registry.RegistryImpl_Stub.rebind"
I thought the problem was that the HotelReservationImpl_Stub.class could not be found but I have manually created this in the classes directory so I presume it should be picked up.
Any ideas here?
Thanks.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5610
    
  15

Hi Mark,

This is the code I used to register my service:

Maybe you could try it like that.

Are you working on a linux machine? If it still doesn't work, maybe posting full stacktrace could point out the problem. Anyway don't create stub-class manually: from JDK 5 this is done automatically, so no need to create it yourself.

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Mark O' Sullivan
Ranch Hand

Joined: Aug 17, 2009
Posts: 160
Cheers, thanks for that.
I orginally had this.

and following Roel's kind suggestion changed it to:

I also had therefore to change the code to retrieve the object from

to

Clearly also had to remove the UnicastRemoteObject defintion from the HotelReservationImpl class as well.
Thanks the help and if anyone could explain the different between the 2 methods?
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5610
    
  15

Hi Mark,

I think it would have worked with just extending from UnicastRemoteObject (and so not using exportObject-function) too.

But I used the exportObject-method because in Java you have no multiple inheritance, so if you already extend from UnicastRemoteObject you can't extend anymore from another class.

Why it doesn't work with the Naming.rebind() I don't have an idea.

Kind regards,
Roel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem running Naming.rebind in RMI