Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem running Naming.rebind in RMI

 
Mark O' Sullivan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 10392
133
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mark O' Sullivan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 10392
133
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic