CosminO
CosminO

Reputation: 5226

Java RMI Connection refused

From the policy file:

permission java.net.SocketPermission "localhost:1024-", "listen, resolve";
permission java.net.SocketPermission "localhost:1099", "connect, resolve";
permission java.net.SocketPermission "localhost:1024-", "connect, resolve";
permission java.net.SocketPermission "localhost:1024-", "accept, resolve";

Having this code:

remoteObjName = "blabla";
final objectInterface engine = new object();
final Remote stub = UnicastRemoteObject.exportObject(engine, 0);
final Registry registry = LocateRegistry.getRegistry();
registry.rebind(remoteObjName, stub);//this line causes the exception.

What could cause this exception, on the last line registry.rebind(remoteObjName, stub);:

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(Unknown Source)
        at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
        at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
        at sun.rmi.server.UnicastRef.newCall(Unknown Source)
        at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)
        at app.ConnectionHandler$QAProbeRemote.startEngine(ConnectionHandler.java:47)
        at app.Main.<init>(Main.java:71)
        at app.Main$1.run(Main.java:49)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$000(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.awt.EventQueue$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: java.net.ConnectException: Connection refused: connect
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(Unknown Source)
        at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
        at java.net.PlainSocketImpl.connect(Unknown Source)
        at java.net.SocksSocketImpl.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at java.net.Socket.<init>(Unknown Source)
        at java.net.Socket.<init>(Unknown Source)
        at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
        at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
        ... 22 more

Upvotes: 0

Views: 5031

Answers (2)

Sagi Sulimani
Sagi Sulimani

Reputation: 86

You need to start "rmiregistry" registry that found in the JRE folder.

For example, let's say your JRE folder is in: C:\Program Files\Java\jre1.8.0_271\bin

You can go to that folder and run rmiregistry.exe

The rmiregistry.exe will run in a console. Leave it in background.

If you prefer to do it through cmd, follow this:

Open cmd, and write:

cd C:\Program Files\Java\jre1.8.0_271\bin

Hit 'Enter', and then write:

start rmiregistry

And hit 'Enter' again.

Upvotes: 0

jtahlborn
jtahlborn

Reputation: 53674

you haven't started the registry, hence, the connection fails.

Upvotes: 2

Related Questions