java.rmi.ConnectException: Connection refused to host:;

    java.rmi.ConnectException: Connection refused to host:; nested exception is: Connection refused
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(
    at sun.rmi.transport.tcp.TCPChannel.createConnection(
    at sun.rmi.transport.tcp.TCPChannel.newConnection(
    at sun.rmi.server.UnicastRef.invoke(
    at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(
    at java.rmi.server.RemoteObjectInvocationHandler.invoke(
    at com.sun.proxy.$Proxy0.notifyMe(Unknown Source)
    at CallbackServerImpl.doCallback(
    at CallbackServerImpl.registerForCallback(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at sun.rmi.server.UnicastServerRef.dispatch(
    at sun.rmi.transport.Transport$
    at sun.rmi.transport.Transport$
    at Method)
    at sun.rmi.transport.Transport.serviceCall(
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(
    at sun.rmi.transport.tcp.TCPTransport$
    at java.util.concurrent.ThreadPoolExecutor.runWorker(
    at java.util.concurrent.ThreadPoolExecutor$
    Caused by: Connection refused
    at Method)
    at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(
    at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(
    ... 23 more

I get this exception when I try to connect a remote client to my server. In both, server and client the hostName for the registryUrl of rmi is the public IP address of the server. I also tried to put localhost in server but the error doesn't change.

My java.policy is set to grant all connections to all ports and I have no firewalls enabled in the server or the client.

Any suggestions what could be?

This is item A.1 in the RMI FAQ. You need to either fix your /etc/hosts file or set the java.rmi.server.hostname property at the server.

Unable to connect to remote RMI service when using multi-homed , When connecting to a multi-homed machine using RMI, the wrong address may ConnectException: Connection refused to host:; nested exception is: Connection timed out: connect #113449 - java.rmi.ConnectException: Connection refused to host:; nested exception is: Connection refused This exception might occur when a remote application tries to register itself as an observer/listener with the Web NMS server running in a Linux machine.


I had exactly the same error. When the remote object got binded to the rmiregistry it was attached with the loopback IP Address which will obviously fail if you try to invoke a method from a remote address. In order to fix this we need to set the java.rmi.server.hostname property to the IP address where other devices can reach your rmiregistry over the network. It doesn't work when you try to set the parameter through the JVM. It worked for me just by adding the following line to my code just before binding the object to the rmiregistry:


In this case the IP address on the local network of the PC binding the remote object on the RMI Registry is

java.rmi.ConnectException: Connection refused to host (Distributed , Sometimes in my server log I see exceptions like this: ? 1. 2. java.rmi.​ConnectException: Connection  Please, how are you rsolved this problem ? i try with: java HelloServer -Djava.rmi.server.hostname= but the client cant' find the server java.rmi.ConnectException: Connection refused to host:; nested exception is: Connexion refusée – researcher Dec 10 '14 at 13:08

I found many of the Q&A on this topic, not nothing was helping me - that's because my issue was more basic ( what can I say I am not a networking guru :) ). My ip address in /etc/hosts was incorrect. What I had tried included the following for CATALINA_OPTS:

CATALINA_OPTS="$CATALINA_OPTS -Djava.awt.headless=true -Xmx128M -server
-Djava.rmi.server.hostname=A.B.C.D"  #howeverI put the wrong ip here!


My problem was that I had changed my ip address many months ago, but never updated my /etc/hosts file. it seems that by default the jconsole uses the hostname -i ip address in some fashion even though I was viewing local processes. The best solution was to simply change the /etc/hosts file.

The other solution which can work is to get your correct ip address from /sbin/ifconfig and use that ip address when specifying the ip address in, for example, a script:


fabric:ensemble-add fails with "java.rmi.ConnectException , rmi.ConnectException: Connection refused to host:". Solution Verified - Updated December 20 2016 at 1:07 PM  In order to isolate the problem, I've disabled all connection adapters of my machine. In this case it works fine with but at the time I-ve enabled one connection giving to the machine one IP the problem comes back and sometimes the message conection refused for appears and/or for the other IP.

you can use LocalRegistry such as:

Registry rgsty = LocateRegistry.createRegistry(1888); rgsty.rebind("hello", hello);

Why "Connection refused to host" in , java.rmi.ConnectException: Connection refused to host:; nested exception is: Connection refused:  I have a problem using java rmi: When I'm trying to run my server, I get a connectException (see below). Exception happens when executing the rebind method: Runtime.getRuntime().exec("rmiregistr

Maybe your rmiregistry not be created before client trying connect to your server and it would lead to this exception.In Linux, you can use "netstat" to check your rmiregistry be bond on the right port you assigned in java code.

Java RMI Connection refused to host: localhost; nested exception is , ConnectException: Connection refused: connect. Hello guys! I wouldn't be asking such seemingly stupid question here, but I'm  java.rmi.ConnectException: Connection refused to host:; nested exception is: Connection refused at sun.rmi.transport.tcp

113449, #113449 - java.rmi.ConnectException: Connection refused to host:; nested exception is: Connection refused 

Article: Disabling loopback on Linux Cloud to ensure communication , newConnection( at sun.rmi.server. java.rmi.​ConnectException: Connection refused to host:; nested 

Jmeter, java.rmi.server.hostname property can be set either in file (​which lives under /bin folder of your JMeter installation) or passed 

  • Please, how are you rsolved this problem ? i try with: java HelloServer -Djava.rmi.server.hostname= but the client cant' find the server java.rmi.ConnectException: Connection refused to host:; nested exception is: Connexion refusée
  • @researcher You have to set it at the server JVM. Not the client.
  • @researcher And you also have to provide JVM arguments before the class name, not afterwards.
  • the 'server' is the skeleton side on which the stub was originally created via .export; on the server side modify the implicitly stub embedded ip the client invokes: System.setProperty("java.rmi.server.hostname",""); meaning this is the ip the destination/skeleton/server is approachable
  • @researcher After endless hours of trying this and that, defining the server hostname finally did it! I am so grateful! THANK. YOU.
  • It does work when you 'try to set the parameter through the JVM', by which you presumably mean on the command line. If you use System.setProperty(), you have to set it before exporting the remote object, not just before binding.
  • It wouldn't cause this exception with this stacktrace.
  • Oh but it would, observing it on my Archlinux box now. Creating the registry with LocateRegistry.createRegistry(1099) in my server class rather than getting it with LocateRegistry.getRegistry() solves the problem for me.
  • It solves another problem. It solves 'connection refused' when doing the lookup. This problem is 'connection refused' when calling the remote method.
  • Thanks, I just modify /etc/hosts to point my localhost and hostname to the same ip, as you show, and now all works
  • The Registry does not get bound to If the system property didn't work from the command line you did it wrong.
  • If the port was already occupied you didn't get 'connection refused', and changing the Regsitry to another port didn't fix anything unless you also adjusted the code, and port 1099 was reserved for the RMI Registry by 1996, so whatever alleged process was allegedly already listening to it was severally non-compliant.
  • Welcome to StackOverflow. This doesn't answer the original question.
  • There is no 'must' about it. It's only necessary with misconfigured DNS, or in some multi-homed host situations.