12

I am getting

Caused by: java.net.NoRouteToHostException: No route to host
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 com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:564)
at sun.reflect.GeneratedMethodAccessor638.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:140)
at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(SSLProtocolSocketFactory.java:130)
at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)

javadoc says

Signals that an error occurred while attempting to connect a socket to a remote address and port. Typically, the remote host cannot be reached because of an intervening firewall, or if an intermediate router is down.

Is this error on client side or remote side or it can be either of these?

padis
  • 2,314
  • 4
  • 24
  • 30

6 Answers6

10

Basically it says that your client cannot connect to the server due to the address is inaccessible from the client machine.

Please check that the address you are connecting to is accessible, either via ping command in your Command Prompt (Windows) or terminal (Unix-based):

ping <address>

or if it's a web server you can try to check it in your web browser.
The ping command is helpful for me in most cases, since I would know why exactly I can't connect to the address. It can be a mistyped address or like the javadoc suggests, problem with firewall.

justhalf
  • 8,960
  • 3
  • 47
  • 74
7

Either. It could be a firewall on the client machine blocking outgoing calls or somewhere at the other end.

Qwerky
  • 18,217
  • 6
  • 44
  • 80
5

It may be possible the ping will provide responses, but the application may still fail to connect. If that is the case, I would suggest using telnet to try and connect to the host using the desired port, telnet host.address port

If the connection is refused then the port on the host will need to be allowed. It that succeeds, but the application still won't connect:

  1. Verify the address:port being used in your application are the same as those used in the telnet test.
  2. It may be a local port on the client blocking the connection, in which case you would need to allow the port on the client
Paul Stoner
  • 1,359
  • 21
  • 44
-1

In my case it was solved like this:

1 - Clear the cache with 'yarn cache clean' or 'npm cache clean --force'

2 - after that reboot the pc.

If you clear the cache but do not reboot, the data will still be stored 'somewhere' on the network, so the port will not connect, it is still busy. After restarting it connects smoothly.

I hope I was helpful!

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
-3

I had the same issue, and resolve it by disabling the firewall on both sides :

systemctl disable firewalld

service firewalld stop

  • 1
    Typically, turning off the software firewall is not a good idea, especially in production systems. Please, try adding a viable solution. Maybe a port simple needs to be opened in the firewall. It is better to try and provide some diagnostic tips to find the problem. Don't downvote simply because the answer is not a good one. Provide constructive feedback to help this new user. – Paul Stoner Mar 26 '20 at 14:33
-4

I had the same issue, I did run iptables flush on host server, this fixed the issue.

# iptables --flush 
Ralf Stubner
  • 26,263
  • 3
  • 40
  • 75
Learner
  • 53
  • 6
  • 4
    People downvoted you without explaining why. This is only a last-resort **test** at best and not something to use in a production environment. *It removes all firewall policies from your host.* At best, it leaves your host wide open to a number of connection exploits, in some cases it can even disable networking to the host entirely (if you've set the default to DROP ACCEPT) and the only way to get back from that is console access. – Douglas Adams Jun 05 '19 at 01:04