ErrnoException: isConnected failed: EHOSTUNREACH (No route to host) when changing the wifi network using ICS
Asked Answered
A

5

23

When using my app on ics, after I change my wifi network from networkA to networkB all the requests for images start coming back with an exception.

failed with exception

> org.apache.http.conn.HttpHostConnectException: Connection to
> https://m1.testapp.com refused    at
> org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183)
>   at
> org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
>   at
> org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
>   at
> org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
>   at
> org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
>   at
> org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
>   at
> org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
>   at
> com.testApp.android.ws.PooledRequestProcessor$Runner.run(PooledRequestProcessor.java:298)
>   at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
>   at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
>   at java.lang.Thread.run(Thread.java:856)  Caused by:
> java.net.ConnectException: failed to connect to /109.233.153.38 (port
> 443) after 20000ms: isConnected failed: EHOSTUNREACH (No route to
> host)     at
> org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:181)
>   ... 10 more  Caused by: java.net.SocketException: failed to connect
> to /109.233.153.38 (port 443) after 20000ms: isConnected failed:
> EHOSTUNREACH (No route to host)   at
> libcore.io.IoBridge.isConnected(IoBridge.java:220)    at
> libcore.io.IoBridge.connectErrno(IoBridge.java:152)   at
> libcore.io.IoBridge.connect(IoBridge.java:112)    at
> java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)    at
> java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)    at
> java.net.Socket.connect(Socket.java:842)      at
> org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
>   at
> org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
>   ... 10 more  Caused by: libcore.io.ErrnoException: isConnected
> failed: EHOSTUNREACH (No route to host)   at
> libcore.io.IoBridge.isConnected(IoBridge.java:201)

The strangest thing is that even uninstalling the app and reinstalling it wont fix it, just turning the phone off and on.

I saw a similar problem here http://groups.google.com/group/newsrob/browse_thread/thread/ea2f26d9d1753b79/5800e268eeab399c#5800e268eeab399c . The problem is not happening on phones with 4.0.3, just on the ones with 4.0.1, and the update doesnt seem to be available in Europe yet.

Assibilate answered 9/1, 2012 at 10:53 Comment(0)
B
2

Maybe it's taking a while for the switch over to take place for some reason? You can check to see if there is an active network connection before making the request:

ConnectivityManager connectivityManager = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo                 = connectivityManager.getActiveNetworkInfo();

if (networkInfo != null && networkInfo.isConnected() && networkInfo.isAvailable())
{
    // DO WHAT YOU NEED TO DO ON THE NETWORK
}
else
{
    // PROMPT USER THAT NETWORK IS DISCONNECTED

        Toast.makeText(this, "There is no active network connection!", 5000).show();
}
Bodi answered 27/8, 2012 at 14:37 Comment(0)
M
0

While switching and establishing with new network device may take some time. The below code may help you.

ConnectivityManager connMngr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
try {
    return connMngr.getActiveNetworkInfo().isConnectedOrConnecting();
}
catch (NullPointerException npe) {
    return false;
}
Moslemism answered 2/1, 2013 at 12:42 Comment(0)
W
0

Looks like you have problem with TCP protocol. It maybe in case weak WiFi or 3G signal. Use try/catch for it.

Williamson answered 15/7, 2014 at 10:27 Comment(0)
N
0

failed: EHOSTUNREACH (No route to host)

So the routing has not been set up correctly.

I found that for some devices you have to set the WifiConfiguration’s ipAssignment field to WifiConfiguration.IpAssignment.DHCP manually for that a DHCP request is performed after changing the wifi programatically. This can only be done via reflection, see this answer how to code it. Catch all exceptions, because on other devices the field does not even exist.

Ninnetta answered 15/7, 2015 at 6:42 Comment(0)
R
0

I had the same problem this is how I solved it.

  1. Disable your firewalls

  2. go to your server folder (in my case I was using Node.js) the WWW file and listen on the provided port, on all network interfaces.

    server.listen(port, ip);

     server.on('error', onError);
     server.on('listening', onListening);
    
  3. Make sure the IP address is your local network IP, on widows this can be gotten by typing ipconfig on command prompt.

  4. restart the server and try connecting again.

Radiobroadcast answered 21/8, 2018 at 3:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.