File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Distributed Java and the fly likes RMI  * java.net.ConnectException * occurs when client on remote computer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "RMI  * java.net.ConnectException * occurs when client on remote computer" Watch "RMI  * java.net.ConnectException * occurs when client on remote computer" New topic
Author

RMI * java.net.ConnectException * occurs when client on remote computer

Vince Hon
Ranch Hand

Joined: Feb 11, 2003
Posts: 117
Hi,
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: 10.0.213.128;
nested exception is:
java.net.ConnectException: 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://vincehon.no-ip.com/RmiServer");
where "vincehon.no-ip.com" 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="http://vincehon.homeip.net:8000/VJW" target="_blank" rel="nofollow">http://vincehon.homeip.net:8000/VJW</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 127.0.0.1, your naming service stores this:
//127.0.0.1/RmiServer
When you go to look for it from the same machine it finds it fine since 127.0.0.1 points back to itself, but when you try to find it from somewhere else, your Naming.lookup is looking for something like this:
//10.0.213.128/RmiServer
And the request gets to your machine, and to your RMIRegistry, but you have your server bound to:
//127.0.0.1/RmiServer
which doesn't match
//10.0.213.128/RmiServer
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 10.0.213.128 into the rebind if that was a permanent ip. My way is a bit disjointed, but it works.
Hope this helps,
Chris
[ 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 10.0.213.128 and vincehon.no-ip.com in the program:
i.e. In the Server
Naming:rebind("//vincehon.no-ip.com/RmiServer", this);
But the same problem occurs, java.net.ConnectException...
However, when I use:
"java -Djava.rmi.server.hostname=vincehon.no-ip.com RmiServer"
where "RmiServer" is the class name of my server program
It works !! But it will not works if "java -Djava.rmi.server.hostname=127.0.0.1 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: http://aspose.com/file-tools
 
subject: RMI * java.net.ConnectException * occurs when client on remote computer
 
Similar Threads
Why can't client connect to RMI server on same machine?
packaging final application
RMI app - java.rmi.ConnectException
RMI Exception
RMI client server don't work on ipv6 machines