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 Callback calls 127.0.1.1 instead of real client IP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Callback calls 127.0.1.1 instead of real client IP" Watch "Callback calls 127.0.1.1 instead of real client IP" New topic
Author

Callback calls 127.0.1.1 instead of real client IP

Andrea Guarini
Greenhorn

Joined: Apr 26, 2010
Posts: 4
Hi all, I'd like to ask a question.. it may sound easy but I'm stuck with it.
I have successfully implemented a callback architecture in my program, but it works only if the server and client programs are on the same machine. If I load the client on another machine the client can call any rmi method on the server, but when it's time to use a callback method the server tries to connect to 127.0.1.1.
Should I set java.hostname property also on the client? I don't think so, but never say never..

simplified versions of the sources:



Log of the server console:

RmiDelegate.printRemotely()
java.rmi.ConnectException: Connection refused to host: 127.0.1.1; nested exception is:
java.net.ConnectException: Connection refused
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:110)
at Root.Dominio.ServerDelegate_Stub.printMessage(ServerDelegate_Stub.java:55)
at Root.Rmi.RmiDelegate.printRemotely(RmiDelegate.java:116)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at java.net.Socket.<init>(Socket.java:366)
at java.net.Socket.<init>(Socket.java:180)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:595)
... 19 more

Scripts I use to run the server and the clients:
client:
java -Djava.security.policy=security.policy -jar Client.jar

server:
java -Djava.security.policy=security.policy -Djava.rmi.server.hostname=192.168.1.254 -Djava.rmi.server.codebase=file:/home/Server/Client.jar -jar Server.jar

Can somebody figure out what's wrong in my code?
Thanks in advance, Andrea.
Andrea Guarini
Greenhorn

Joined: Apr 26, 2010
Posts: 4
I should have set the hostname property also on the client...
I thought the UnicastRemoteObject.exportObject told the server everything it needed to call the clients.
If I have a client which runs on dhcp how should I set this property?
Now I'm in a LAN setting, so I simply put the local IP address of my client machine. Should I put the public IP address?
Mike Peters
Ranch Hand

Joined: Oct 10, 2009
Posts: 67

Normally a client also has a name on the network you could use that in the property (e.g. client.local). I hope this helps.


Mike Peters
Borys Zora
Greenhorn

Joined: Aug 05, 2012
Posts: 1
1) host = "192.168...."
or
2) hostName = InetAddress.getByName(host).getHostAddress();

1) System.setProperty("java.rmi.server.hostname", host);
or
2) System.setProperty("java.rmi.server.hostname", hostName);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Callback calls 127.0.1.1 instead of real client IP
 
Similar Threads
RMI problem
RMI connection to registry refused
RMI 003
ConnectRefused in RMI
referenced and last confusion