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 RMI Rebind question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RMI Rebind question" Watch "RMI Rebind question" New topic
Author

RMI Rebind question

Kj�ttleif S�dbank
Greenhorn

Joined: Jun 08, 2005
Posts: 2
I have been working on my assignment for about 2 months now, and I am getting close to delivery time

This forum has really been a great help for me! This is the first time I post a message and the reason is that I am really stuck

The problem is my server rmi implementation. This is the code I am trying to use:
java.rmi.registry.LocateRegistry.createRegistry(port);
Naming.rebind("TestServer", c);

But this only works when I disable my network connection
Otherwise I get this error message:
"Connection refused to host: 192.168.0.102; nested exception is:
java.net.ConnectException: Connection refused: connect"

This, however, works:
Naming.rebind("rmi://localhost/TestServer", c);

Anyone have a clue?

Thanx in advance!!

/Kj�ttleif
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

Hi Kj�ttleif,

Welcome to JavaRanch and this forum.

Are you running NAT?

The RMI reference implementation provided by Sun does not allow for the RMI registry to reside on one machine and the service to reside on another machine. If either the registry or the service were believing the other was remote due to network address translation this could cause the problem you are seeing.

There are ways around this, but I wonder whether it is necessary: you do, after all, have a workaround . But if you would like to know more, just ask.

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Kj�ttleif S�dbank
Greenhorn

Joined: Jun 08, 2005
Posts: 2
Hi Andrew,

Thanks a lot for your response

From what I understand I am running NAT. Does this mean that this is not a problem when I deliver my assignment?

Do you know why this works?
"Naming.rebind("rmi://localhost/TestServer", c);"

I thought that the first argument just was the name of the server and that it did not matter what you wrote there...

Regards,
Kj�ttleif
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

Hi Kj�ttleif,
From what I understand I am running NAT. Does this mean that this is not a problem when I deliver my assignment?


Correct.

Do you know why this works?
"Naming.rebind("rmi://localhost/TestServer", c);"
I suspect that when the RMI Registry is starting up, it is binding to the localhost. When your service tries to do a rebind without any server name, it does a generic call to the IP address of your computer which is getting translated. So the registry is rejecting it since the address of the service is not the same as the localhost address.

When you explicitly put localhost into the service's call to rebind, you are ensuring that the two addresses will match.

I thought that the first argument just was the name of the server and that it did not matter what you wrote there...
It is possible to tell the registry to only listen to calls on a particular IP address. This might be useful on a computer with multiple IP addresses - such as on a firewall or a DMZ. In such a case you would want to be able to specify in the call to rebind which registry you wish to bind to.

This is way beyond the requirements of 90% of RMI users (and completly out of scope for the SCJD assignment), so it is often not mentioned. You can find some information on this if you hunt for it, or get an advanced book on RMI. This JGuru page shows some of the ways around firewalls (which you can possibly extrapolate to see how it can be used in a multi-IP environment).

Regards, Andrew
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RMI Rebind question
 
Similar Threads
java.rmi.ConnectException: Connection refused to host
Problem running Naming.rebind in RMI
Client/Server command line options
RMI and DHCP in the SCJD
RMI fails to connect between XP and Linux