Problem connecting 2 machines
My application runs ok when i do it localy but when i run server in a different machine i get the follwing error. This happen after i connect to the server :
--
Exception in thread "main" java.rmi.RemoteException: connection failed to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection refused
at gnu.java.rmi.server.UnicastRef.invokeCommon(libgcj.so.7)
at gnu.java.rmi.server.UnicastRef.invoke(libgcj.so.7)
at PowerServiceServer_Stub.power(Unknown Source)
at PowerServiceClient.main(PowerServiceClient.java:76)
Caused by: java.net.ConnectException: Connection refused
at gnu.java.net.PlainSocketImpl.connect(libgcj.so.7)
at java.net.Socket.connect(libgcj.so.7)
at java.net.Socket.connect(libgcj.so.7)
at java.net.Socket.<init>(libgcj.so.7)
at java.net.Socket.<init>(libgcj.so.7)
at gnu.java.rmi.server.RMIDefaultSocketFactory.createSocket(libgcj.so.7)
at gnu.java.rmi.server.UnicastConnectionManager.getClientConnection(libgcj.so.7)
at gnu.java.rmi.server.UnicastConnectionManager.getConnection(libgcj.so.7)
at gnu.java.rmi.server.UnicastRef.invokeCommon(libgcj.so.7)
...3 more
--
This is how i call registry in the client code, where args[0] i give as an input before the program runs (for example cs4489.in.cs.xxx.xx)
PowerService service = (PowerService) Naming.lookup
("rmi://" + args[0] + "/PowerService");
And this is the code in the server code in machine 2
PowerServiceServer svr = new PowerServiceServer();
Naming.bind ("PowerService", svr);
PowerServise is interface class
[1683 byte] By [
Lakiscya] at [2007-11-26 17:39:02]

# 1
Use ip address of the host computer rather than the loopback address 127.0.0.1. For example if IP address of the computer running the server is 179.23.56.25 usejava Client 179.23.56.25
# 2
Thanks for reply but...Why is trying to connect at 127.0.0.1? That isnt the address i give to connect. Im working in my university labatories network it should worked, by giving the name of the machine. I also checked the firewalls are disabled and the port is availble
# 3
> This is how i call registry in the client code, where
> args[0] i give as an input before the program runs
> (for example cs4489.in.cs.xxx.xx)
>
> PowerService service = (PowerService) Naming.lookup
> ("rmi://" + args[0] + "/PowerService");
>
I am not familiar with this. why does it start with rmi://? I use simply the hostname and port of registry like so
"//hostname:1099/Servername"
> And this is the code in the server code in machine 2
>
> PowerServiceServer svr = new PowerServiceServer();
> Naming.bind ("PowerService", svr);
>
> PowerServise is interface class
That is how I do my server as well.
# 4
You are using the useless GNU java. Delete it and install a Sun JDK.
ejpa at 2007-7-9 0:07:12 >

# 5
Thanks for your replies
I use what you said in the previus posts. Im totaly sure that i connect to the server machine, because if it cant find host the message is diferent.
The problem is when it tries to return the result from the remote method.
Also, i cant install JDK because im not the administrator of those machines.
Why is trying to find the loopback address 127.0.0.1?
# 6
Ok I change to JDK but now i i have a more serius problem.
I get this error when i run the server
--
Exception in thread "main" java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
at java.security.AccessController.checkPermission(AccessController.java:427)
.
.
.
--
# 7
Ok i solved the previus error by adding this code to the client and server
System.setProperty("java.security.policy", "policy_client.all");
And by running the program with the following command
java -Djava.rmi.server.codebase -Djava.security.policy <filename>
The program is running but im back to my first error again :D
Nothing changed
I still get "Connection refused to host 127.0.0.1 ......"
# 8
> And by running the program with the following
> command
>
> java -Djava.rmi.server.codebase -Djava.security.policy <filename>
That doesn't accomplish anything. You need to set the properties to values.
Also why are you trying to set java.security.policy on the command line and in the code?
ejpa at 2007-7-9 0:07:12 >

# 9
> That doesn't accomplish anything. You need to set the
> properties to values.
I really dont understand
> Also why are you trying to set java.security.policy
> on the command line and in the code?
I dont know i read it from another forum.
You see my server is running properly. Also the client is running properly. The error i get is not when i try to execute the client file.
The error appears after i run the client, when is trying to calculate the result, from the remote method from server.
Thats what i dont understand. What i should do
# 10
> I really dont understand
java -Djava.rmi.server.hostname=<IP address of server> -Djava.security.policy=<URL of policy file>
> > Also why are you trying to set
> java.security.policy
> > on the command line and in the code?
>
> I dont know i read it from another forum.
I don't think so. If you did it was rubbish. You either set a property with -D on the command line or in the code. If you set it on both, the setting in the code overrides the setting on the command line.
> What i should do
Set java.rmi.server.hostname at the server JVM to the correct public IP address of the server, as shown above.
ejpa at 2007-7-9 0:07:12 >

# 11
> Set java.rmi.server.hostname at the server JVM to the> correct public IP address of the server, as shown> above.Ok i understand now, but what if in my client code i call remote methods from more than 1 server? How i will give all the ip's of the servers i
# 12
Nothing to do with the client. Set it at the servers to the public IP address of the server in each case.
ejpa at 2007-7-9 0:07:12 >

# 13
Please can you be more specific, how i will do that? Im new my knowleage is not very good.
# 14
Set java.rmi.server.hostname at the server JVM to the correct public IP address of the server, as shown above.I don't know how to put it any plainer than that without repeating myself 1000 times.
ejpa at 2007-7-9 0:07:12 >

# 15
Thank you very much. Is working and sorry for the duplicated quenstions :).Now i will try to use more machines.