What does ConnectionRefusedException mean?

You usually get this exception if your server is either not running, or is not running on the host and port specified in the proxy used by the client.

The best way to debug this is to first run the server with network tracing (property Ice.Trace.Network=2) to determine on which host/port the server is listening. For example, if you run the "hello" demo server, you will get tracing output that looks similar to this:

$ ./server --Ice.Trace.Network=2
-- ./server: Network: attempting to bind to tcp socket 192.168.1.34:10000
-- ./server: Network: accepting tcp connections at 192.168.1.34:10000
-- ./server: Network: attempting to bind to udp socket 192.168.1.34:10000
-- ./server: Network: starting to receive udp packets
   local address = 192.168.1.34:10000
-- ./server: Network: attempting to bind to ssl socket 192.168.1.34:10001
-- ./server: Network: accepting ssl connections at 192.168.1.34:10001
-- ./server: Network: published endpoints for object adapter `Hello':
   tcp -h 192.168.1.34 -p 10000:udp -h 192.168.1.34 -p 10000:ssl -h 192.168.1.34 -p 10001

From the tracing output, you can see that the server listens on three endpoints:

  • Incoming TCP connections on host 192.168.1.34, port 10000
  • Incoming UDP packets on host 192.168.1.34, port 10000
  • Incoming SSL connections on host 192.168.1.34, port 10001

The last log message also provides a potentially relevant bit of information: the endpoints that the object adapter publishes in the proxies it creates.

Now try running the client with network tracing. For example, if the client has the wrong host information, you would get tracing like that shown below:

$ ./client --Ice.Trace.Network=2
[ Network: trying to establish tcp connection to 192.168.1.59:10000 ]
[ Network: trying to establish ssl connection to 192.168.1.59:10001 ]
[ Network: trying to establish tcp connection to 192.168.1.59:10000 ]
[ Network: trying to establish ssl connection to 192.168.1.59:10001 ]
Network.cpp:1243: Ice::ConnectionRefusedException: connection refused: Connection refused

From the information above, you can see that the client is trying to connect to 192.168.1.59 instead of 192.168.1.34. There are several reasons why this could happen:

  • The client's configuration might contain a simple typo in the proxy endpoints.
  • Your DNS (name server) might not be set up properly. Try looking up the server's host name with "nslookup" or similar tools to see if DNS returns the correct IP address for the server name.
  • Perhaps your server has two IP addresses, but you didn't configure which one it should use.
  • If the client did not manufacture the proxy locally (such as from a configuration property or string) but rather obtained it as the result of an Ice invocation, the server that supplied the proxy may not be configured correctly.
  • The client may be configured to use a router or locator, in which case the initial connection attempt being logged is not necessarily an invocation on the target server but rather an attempt to use an intermediary service.

Of course there are many other possible reasons. With the help of the tracing output, you should be able to find out where the problem lies.

See Also