RMI Client Code Issue

Hello,

Here is my client side RMI program:

import java.rmi.*;

publicclass MyRemoteClient{

publicstaticvoid main(String args[]){

MyRemoteClient mm =new MyRemoteClient();

mm.go();

}

publicvoid go(){

try{

MyRemote service2 = (MyRemote) Naming.lookup("rmi://xxx.xxx.xx.xx/Hello");

String s = service2.sayHello();

System.out.println(s);

}catch(Exception ex){ex.printStackTrace();}

}

}

Having started RMI Registry and Service Implementor code on the server, if I try to run the above code on the client it fire the following error:

java.rmi.ConnectException: Connection refused to host: 127.0.1.1; nested exception is:

java.net.ConnectException: Connection refused: connect

at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)

at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)

at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)

at sun.rmi.server.UnicastRef.invoke(Unknown Source)

at MyRemoteImpl_Stub.sayHello(Unknown Source)

at MyRemoteClient.go(MyRemoteClient.java:11)

at MyRemoteClient.main(MyRemoteClient.java:6)

Caused by: java.net.ConnectException: Connection refused: connect

at java.net.PlainSocketImpl.socketConnect(Native Method)

at java.net.PlainSocketImpl.doConnect(Unknown Source)

at java.net.PlainSocketImpl.connectToAddress(Unknown Source)

at java.net.PlainSocketImpl.connect(Unknown Source)

at java.net.SocksSocketImpl.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at java.net.Socket.<init>(Unknown Source)

at java.net.Socket.<init>(Unknown Source)

at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)

at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)

... 7 more

I am wondering as to why is it trying to connect to a local host 127.0.1.1 instead of the IP Address specified at by"xxx.xx.xx.xx" in the program?

I have the stub class and the service interface classes on my client-side.

Thanks.

[2886 byte] By [Javajockeya] at [2007-11-26 18:47:26]
# 1

> I am wondering as to why is it trying to connect to a

> local host 127.0.1.1 instead of the IP Address

> specified at by"xxx.xx.xx.xx" in the program?

Because that only specifies where the lookup should be done, i.e. where the Registry is. This lookup() returns a stub to your remote object which has its own IP address and port embedded into it, and that's where 127.0.0.1 is coming from - you're not doing Registry.lookup at this point, you're calling your remote method.

This indicates a DNS or /etc/hosts misconfiguration - your primary IP address is coming up as 127.0.0.1 instead of whatever your public IP address is. Famous Linux issue. You should really fix it in your DNS or /etc/hosts, but you can work around it by setting -Djava.rmi.server.hostname=<public IP address> at the server JVM.

ejpa at 2007-7-9 6:21:24 > top of Java-index,Core,Core APIs...