I am trying to run a simple rmi application. However I’ve run into unexplainable (to me) error.
I have my object CheckerImplementation that implements remote interface Checker. I am trying to set it up with this code [Instance() returns an object of CheckerImplementation type]:
try
{
Checker stub = (Checker) UnicastRemoteObject.exportObject(Instance(), 0);
// Bind the remote object's stub in the registry
Registry registry = LocateRegistry.getRegistry();
registry.bind("Checker", stub);
System.err.println("Server ready");
}
catch (Exception e)
{
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
When run, i get the following exception:
java.rmi.ConnectException: Connection refused to host: 10.105.124.34; nested exception is:
java.net.ConnectException: Connection refused: connect
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.newCall(UnicastRef.java:322)
at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
at Checker.CheckerImplementation.main(CheckerImplementation.java:172)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:189)
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)
... 5 more
Why is Java trying to connect to 10.105.124.34 anyway? That is not localhost. What could be the raeason and how can this be fixed?
After doing some experimentation i figured out that 10.105.124.34 is indeed my IP adress. But the question remains: why not 127.0.0.1?
Are you sure
10.105.124.34isn’t your local IP? Runifconfig/ipconfig. This is the code responsible for choosing this address (java.rmi.registry.LocateRegistry#getRegistry):To wrap it up: you need RMI registry (server) running locally on your computer. Apparently you are trying to connect to it (port 1099) but none is running.