RMI Connection Refused
Hi,
I am writing a RMI application, I have the client on my laptop (Windows XP Pro) and the server application on my Desktop (Fedcore 6). When ever I have the server application on the Desktop with the rmiregistry program running, the client application gets the following exception: -
Exception in thread "main" java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection refused: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:574)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:185)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:171)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:94)
at rmiserver.Calculator_Stub.add(Unknown Source)
at rmiclient.Main.main(Main.java:38)
Caused by: java.net.ConnectException: Connection refused: connect
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:179)
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:569)
... 5 more
Java Result: 1
Now the code tells it to connect to ip address 192.168.1.11 but it keeps changing it to 127.0.0.1. However if I have the server application running on the laptop and the client applicaton on the desktop, the application works fine.
Here is the code for the client: -
package rmiclient;
import java.rmi.*;
import rmiserver.*;
import java.rmi.server.*;
import java.rmi.registry.*;
/**
*
*
*/
publicclass Main{
/** Creates a new instance of Main */
public Main(){
}
/**
* @param args the command line arguments
*/
publicstaticvoid main(String[] args)throws Exception{
System.setProperty("java.security.policy","Security.policy");
if (System.getSecurityManager() ==null){
System.setSecurityManager(new RMISecurityManager());
}
RemoteInterface calc = (RemoteInterface) Naming.lookup("rmi://192.168.1.11/CALC");
System.out.println(calc.add(5, 5));
System.out.println(calc.subtract(10, 5));
System.out.println(calc.divide(7, 5));
System.out.println(calc.multiply(7,7));
}
}
Here is the code for the server: -
package rmiserver;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
/**
*
*
*/
publicclass Main{
/** Creates a new instance of Main */
public Main(){
}
/**
* @param args the command line arguments
*/
publicstaticvoid main(String[] args)throws Exception{
System.setProperty("java.security.policy","Security.policy");
if (System.getSecurityManager() ==null){
System.setSecurityManager(new RMISecurityManager());
}
Registry registry = LocateRegistry.getRegistry();
Calculator calc =new Calculator();
registry.rebind("CALC", calc);
}
}
package rmiserver;
import java.rmi.*;
import java.rmi.server.*;
/**
*
*
*/
publicclass Calculatorextends UnicastRemoteObjectimplements RemoteInterface{
/** Creates a new instance of Calculator */
public Calculator()throws RemoteException{
}
publicdouble add(double x,double y)throws RemoteException{
return x + y;
}
publicdouble subtract(double x,double y)throws RemoteException{
return x - y;
}
publicdouble multiply(double x,double y)throws RemoteException{
return x * y;
}
publicdouble divide(double x,double y)throws RemoteException{
return x / y;
}
}
package rmiserver;
import java.rmi.*;
/**
*
*
*/
publicinterface RemoteInterfaceextends Remote{
publicdouble add(double x,double y)throws RemoteException;
publicdouble subtract(double x,double y)throws RemoteException;
publicdouble multiply(double x,double y)throws RemoteException;
publicdouble divide(double x,double y)throws RemoteException;
Please could you help?

