Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

RMI and packages (Error message: Connection refused to host: 127.0.0.1)

843793Sep 9 2006 — edited Sep 20 2006
Hello everybody,

I'm having trouble connecting to the rmiregistry when I place the client and server in different packages (but on the same host). The setup is as follows (Sorry for the long post, but I'm trying to provide as much info as possible)

An eclipse project with two package (server and client). The server package has a class named FileServer that implements:
public interface FileServerInterface extends Remote{
	public char[] getFile(String filename) throws RemoteException;
}
With a main() that executes (details left out for brevity)
// Start the fileServer RMIinterface 
try {
   server.FileServerInterface f = (server.FileServerInterface) UnicastRemoteObject.exportObject(this, 2006);
    	    
    // Bind the remote object's stub in the registry
    Registry registry = LocateRegistry.getRegistry("localhost");
    registry.bind("FileServer", f);
    } catch(java.rmi.AlreadyBoundException e) {
	System.exit(1);
    } catch(Exception e) {
        System.exit(2);
    }
Now when I connect to the rmiregistry from main() using
Registry registry = LocateRegistry.getRegistry("localhost");
String[] tmp = registry.list();
for(int i = 0; i < tmp.length; i++)
   System.out.println(tmp);

server.FileServerInterface stub = (server.FileServerInterface) registry.lookup("FileServer");
// Read a file
char[] response = stub.getFile("/tmp/fserver/test/test1.txt");

It prints out:
FileServer
<contents of the file>
as expected. If I execute the same code in the package client in a class file named Client's main() method. I get
FileServer
 java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is: 
	java.net.ConnectException: Connection refused
java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is: 
	java.net.ConnectException: Connection refused
	at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:574)
	at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
	at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
	at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:94)
	at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:179)
	at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132)
	at $Proxy0.getFile(Unknown Source)
	at client.Client.main(Client.java:38)
The VM's get executed with the following args
-Djava.rmi.server.codebase="file://${workspace_loc:FileServer}/"
-Djava.security.manager
-Djava.security.policy="${workspace_loc:FileServer}/client/client.policy"
-cp ${workspace_loc:FileServer}/server:${workspace_loc:FileServer}/client:/opt/java/lib:/opt/java/jre/lib:.
(where ${workspace_loc:FileServer} evaluates to '/home/mpr/eclipse/workspace/FileServer') and the client.policy file contains:
grant codeBase "file:/home/mpr/eclipse/workspace/FileServer/-" {
    permission java.security.AllPermission;
};
grant {
    permission java.security.AllPermission;
};
I've tried "telneting" to localhost:1099 and the rmiregistry is running (which the output of 'netstat -l' also shows). I've tried using ordinary socket's in the client to connect to localhost:1099, and this succeeds.

I hope someone here can help me, because I'm running out of ideas (and "googling" hasn't turned anything up).

Kind regards,
Mads

PS. A bit of OS environment info should it be helpful
java -version
java version "1.5.0_08" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03) Java HotSpot(TM) Client VM (build 1.5.0_08-b03, mixed mode, sharing)
cat /etc/hosts.allow
# # /etc/hosts.allow # sshd: 10.0.0.0/255.255.255.0 : ALLOW ALL: localhost : ALLOW # End of file
cat /etc/hosts
# # /etc/hosts: static lookup table for host names # #<ip-address> <hostname.domain.org> <hostname> 127.0.0.1 localhost.localdomain localhost 127.0.0.1 T43.localdomain T43 # End of file
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 18 2006
Added on Sep 9 2006
6 comments
540 views