It's not a secret anymore!
The moose likes Distributed Java and the fly likes RMI  * * occurs when client on remote computer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "RMI  * * occurs when client on remote computer" Watch "RMI  * * occurs when client on remote computer" New topic

RMI * * occurs when client on remote computer

Vince Hon
Ranch Hand

Joined: Feb 11, 2003
Posts: 117
I have a rmi client and server programs. When I run the server and the client on the same computer, everything is fine.
However, when I run the client program on other computer. The following exception occurs :
Connection refused to host:;
nested exception is: Operation timed out: connect
I use the default port (1099):
The server extends "UnicastRemoteObject"
In the server program --- Naming.rebind("//localhost/RmiServer", this);
In the client program --- obj = (RmiInterface) Naming.lookup("rmi://");
where "" is the host name to find my server IP.
note: There will be no problem if both the server and client program run on the same computer.

Vince Hon<br /> <br />SCJP 1.4 | SCWCD | SCBCD <br /><a href="" target="_blank" rel="nofollow"></a>
Chris Shepherd
Ranch Hand

Joined: Jun 27, 2000
Posts: 286
I think your problem *might* be with your Naming.rebind(). I had this problem as well with some recent work I was doing. The problem is that you are using localhost to define the ip address. Since localhost usually points to, your naming service stores this:
When you go to look for it from the same machine it finds it fine since points back to itself, but when you try to find it from somewhere else, your Naming.lookup is looking for something like this:
And the request gets to your machine, and to your RMIRegistry, but you have your server bound to:
which doesn't match
so you get some kind of connection denied error.
The solution to this was to to either hard code your true ip address, or discover it in some way. There may be an easier way than this, but here is what I did.
As you can see, I actually put it in the registry twice. once with the localhost ip and once with the realworld IP. That let me contact it both locally and remotely.
I am running my server side under linux, and that "localtb4ip" I was able to define in my local dns to the specific real world ip. You could probably hard code into the rebind if that was a permanent ip. My way is a bit disjointed, but it works.
Hope this helps,
[ May 27, 2003: Message edited by: Chris Shepherd ]
Vince Hon
Ranch Hand

Joined: Feb 11, 2003
Posts: 117
Thanks for you explantion, Chris.
I have tried to hardcode the and in the program:
i.e. In the Server
Naming:rebind("//", this);
But the same problem occurs,
However, when I use:
"java RmiServer"
where "RmiServer" is the class name of my server program
It works !! But it will not works if "java -Djava.rmi.server.hostname= RmiServer"
I think this matches what you have mentioned before.
Although I have solved the problem, but I still don't know the root of the problem and the meaning of the -Djava.rmi.server.hostname=......
Anyway, thanks u again
I agree. Here's the link:
subject: RMI * * occurs when client on remote computer
It's not a secret anymore!