permaculture playing cards
The moose likes Distributed Java and the fly likes Callback calls instead of real client IP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Callback calls instead of real client IP" Watch "Callback calls instead of real client IP" New topic

Callback calls instead of real client IP

Andrea Guarini

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
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:

java.rmi.ConnectException: Connection refused to host:; nested exception is: Connection refused
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(
at sun.rmi.transport.tcp.TCPChannel.createConnection(
at sun.rmi.transport.tcp.TCPChannel.newConnection(
at sun.rmi.server.UnicastRef.invoke(
at Root.Dominio.ServerDelegate_Stub.printMessage(
at Root.Rmi.RmiDelegate.printRemotely(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at sun.rmi.server.UnicastServerRef.dispatch(
at sun.rmi.transport.Transport$
at Method)
at sun.rmi.transport.Transport.serviceCall(
at sun.rmi.transport.tcp.TCPTransport.handleMessages(
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(
at sun.rmi.transport.tcp.TCPTransport$
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(
at java.util.concurrent.ThreadPoolExecutor$
Caused by: Connection refused
at Method)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(
... 19 more

Scripts I use to run the server and the clients:
java -jar Client.jar

java -Djava.rmi.server.hostname= -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

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

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

1) System.setProperty("java.rmi.server.hostname", host);
2) System.setProperty("java.rmi.server.hostname", hostName);
Have you checked out Aspose?
subject: Callback calls instead of real client IP
jQuery in Action, 3rd edition