Reputation: 3608
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?
Upvotes: 2
Views: 4909
Reputation: 1
Start -> cmd -> rmiregistry , close 2 cmd windows. Run your server code again.
Upvotes: -1
Reputation: 340713
Are you sure 10.105.124.34
isn't your local IP? Run ifconfig
/ipconfig
. This is the code responsible for choosing this address (java.rmi.registry.LocateRegistry#getRegistry
):
if (port <= 0)
port = Registry.REGISTRY_PORT;
if (host == null || host.length() == 0) {
// If host is blank (as returned by "file:" URL in 1.0.2 used in
// java.rmi.Naming), try to convert to real local host name so
// that the RegistryImpl's checkAccess will not fail.
try {
host = java.net.InetAddress.getLocalHost().getHostAddress();
} catch (Exception e) {
// If that failed, at least try "" (localhost) anyway...
host = "";
}
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.
Upvotes: 3
Reputation: 112356
Well, you can be pretty certain that it's throwing that exception because it's trying to connect to 10.105.124.34 for some reason, and it's not working.
Here's a suggestion: what's the IP address on the machine on which you're running this? 10.105.124.34 is in the old BBN class A network that everyone uses as an anonymous inside-the-NAT network nowadays, so I'm betting that's what your router is assigning your machine via DHCP. (Hint: ifconfig
on UNIX, ipconfig
on Windows.)
If so, are you actually running the RMI service? What would be answering the call when you bind?
Upvotes: 1