Win a copy of Spring in Action (5th edition) this week in the Spring forum!

Andrea Guarini

Greenhorn
+ Follow
since Apr 26, 2010
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Andrea Guarini

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?
8 years ago
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.
8 years ago
Thank you so much! The problem was I implemented start() instead of run().
8 years ago
Hi guys, I need help about this problem: the application I'm working on is a java gestional software. I recently have implemented RMI callbacks so that the server can trigger updates on clients. After one of the clients does some modifications the server calls the refresh method of the other clients connected to refresh their opened jtables.
The situation that's giving me problem is the following:
client A opens table 1
client A views record 5
client B opens table 1
client B views record 5
client C opens table 1
client C views record 5
client A modifies record 5
server sends an update to all of the clients that currently have opened table 1. If one client has opened the record 5 the purpose of the update is to have a JOptionPane showed that asks if the user (in this case clients B and C) wants to update the visualization of record 5 with the changes made by client A or wants to keep the old version, in the case he has done some modifications he wants to commit later).

obviously if I have more clients currently looking at table 1 record 5 this JOptionPane should show on every machine.
Everytime a client connects it registers itself in an arraylist stored on the server, so when I have to call all of the clients I loop over this arraylist.
The loop on the server goes like this:

for(every client connected)
if it's not the author of the operation (in this case if it's not client A)
show JOptionPane
if the user clicks on YES
refresh()

The problem is that the loop goes on only after the previous client has decided what to do, so the JOptionPane won't show on client C until B has decided to update or not the frame and so on.
I tried modifying the previous loop so that each JOptionPane is handled by a different thread, like this:

for(every client connected)
if it's not the author of the operation (in this case if it's not client A)
{
RefreshThread d = new RefreshThread();
d.start();
}
private class RefreshThread extends Thread
{
@Override
public synchronized void start()
{
if it's not the author of the operation (in this case if it's not client A)
show JOptionPane
if the user clicks on YES
refresh()
}
}

but still no changes, the loop goes on only after the previous client has chosen to update or not.
I thought of implementing my own class to show the message, but if I create a class that shows a window with the message and two buttons (update / cancel) and set it to modal, so that the user cannot bypass it I think the thread on the server will have the same behaviour, it will wait until the modal dialog is closed.
Please give me some hints on how to correct this.
Andrea
8 years ago