android.system.ErrnoException: connect failed: EHOSTUNREACH (No route to host)

  1. 0

    android failed to connect to other device despite in same network

    Stack Overflow | 3 months ago | ujjwal mainali
    android.system.ErrnoException: connect failed: EHOSTUNREACH (No route to host)
  2. 0

    ConnectException/ETIMEDOUT with retrofit/OkHttp

    GitHub | 1 year ago | geovanisouza92
    android.system.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)
  3. 0

    Android socket ConnectException ENETUNREACH

    Stack Overflow | 8 months ago | user1122549
    java.net.ConnectException: failed to connect to SERVERIP (port 8080): connect failed: ENETUNREACH (Network is unreachable) Server code - public class ServerThread implements Runnable { public void run() { try { if (SERVERIP != null) { handler.post(new Runnable() { @Override public void run() { serverStatus .setText("Listening on IP: " + SERVERIP); } }); serverSocket = new ServerSocket(8080); while (true) { // LISTEN FOR INCOMING CLIENTS Socket client = serverSocket.accept(); handler.post(new Runnable() { @Override public void run() { serverStatus2.setText("Connected."); } }); try { BufferedReader in = new BufferedReader( new InputStreamReader( client.getInputStream())); String line = null; while ((line = in.readLine()) != null) { final String currLine = line; Log.i("Server Activity",currLine); handler.post(new Runnable() { @Override public void run() { String origString = serverStatus2.getText().toString(); String newString = origString + "\n" + currLine; serverStatus2.setText(newString); ToneGenerator tone = new ToneGenerator(AudioManager.STREAM_NOTIFICATION,90); tone.startTone(ToneGenerator.TONE_PROP_ACK,10); } }); } break; } catch (Exception e) { handler.post(new Runnable() { @Override public void run() { serverStatus .setText("Oops. Connection interrupted. Please reconnect your phones."); } }); e.printStackTrace(); } } } else { handler.post(new Runnable() { @Override public void run() { serverStatus .setText("Couldn't detect internet connection."); } }); } } catch (final Exception e) { handler.post(new Runnable() { @Override public void run() { serverStatus.setText("Error" + e.getMessage()); } }); e.printStackTrace(); } } } // GETS THE IP ADDRESS OF YOUR PHONE'S NETWORK private String getLocalIpAddress() { try { for (Enumeration<NetworkInterface> en = NetworkInterface .getNetworkInterfaces(); en.hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf .getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { return inetAddress.getHostAddress().toString(); } } } } catch (SocketException ex) { Log.e("ServerActivity", ex.toString()); } return null; } @Override protected void onStop() { super.onStop(); try { // MAKE SURE YOU CLOSE THE SOCKET UPON EXITING serverSocket.close(); } catch (IOException e) { e.printStackTrace(); } } Client - public class ClientThread implements Runnable { public void run() { try { if (socket==null){ initSocketConn(); } //connected = true; //while (connected) { try { Log.d("ClientActivity", "C: Sending command."); if (out==null){ out = new PrintWriter( new BufferedWriter(new OutputStreamWriter( socket.getOutputStream())), true); } // WHERE YOU ISSUE THE COMMANDS out.println(edtMessage.getText().toString()); Log.d("ClientActivity", "C: Sent."); } catch (Exception e) { Log.e("ClientActivity", "S: Error", e); } //} //socket.close(); Log.d("ClientActivity", "C: Closed."); } catch (Exception e) { Log.e("ClientActivity", "C: Error", e); connected = false; } } } private void initSocketConn(){ try{ InetAddress serverAddr = InetAddress.getByName(serverIpAddress); Log.d("ClientActivity", "C: Connecting..."); socket = new Socket(serverAddr, 8080); //THIS IS WHERE THE ERROR IS THROWN } catch (Exception ex){ ex.printStackTrace(); } } I have checked online & tried different options like using different port number but it has not worked. I am confused why the code works perfectly when the Moto is server but gives the error when NExus is Server??? Please help! Logcat - 03-29 07:25:06.065 20592-20611/com.shriwas.samplesocketapp D/OpenGLRenderer: endAllActiveAnimators on 0xb7ca02d8 (RippleDrawable) with handle 0xb7d24240 03-29 07:25:08.957 20592-21470/com.shriwas.samplesocketapp D/ClientActivity: C: Connecting... 03-29 07:25:08.958 20592-21470/com.shriwas.samplesocketapp W/System.err: java.net.ConnectException: failed to connect to /fe80::8c3a:e3ff:fe5d:2e0d%p2p0%25 (port 8080): connect failed: ENETUNREACH (Network is unreachable) 03-29 07:25:08.963 20592-21470/com.shriwas.samplesocketapp W/System.err: at libcore.io.IoBridge.connect(IoBridge.java:124) 03-29 07:25:08.963 20592-21470/com.shriwas.samplesocketapp W/System.err: at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183) 03-29 07:25:08.963 20592-21470/com.shriwas.samplesocketapp W/System.err: at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:163) 03-29 07:25:08.963 20592-21470/com.shriwas.samplesocketapp W/System.err: at java.net.Socket.startupSocket(Socket.java:590) 03-29 07:25:08.963 20592-21470/com.shriwas.samplesocketapp W/System.err: at java.net.Socket.<init>(Socket.java:226)
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Connection Refused in Ionic on Android

    GitHub | 2 years ago | jstevej
    android.system.ErrnoException: connect failed: ECONNREFUSED (Connection refused)
  6. 0

    GitHub comment 1792#153943044

    GitHub | 1 year ago | droidmonkey
    java.net.ConnectException: failed to connect to mbus.doublemap.com/54.152.32.182 (port 80) after 10000ms: isConnected failed: EHOSTUNREACH (No route to host) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at libcore.io.IoBridge.isConnected(IoBridge.java:238) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at libcore.io.IoBridge.connectErrno(IoBridge.java:171) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at libcore.io.IoBridge.connect(IoBridge.java:122) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at java.net.Socket.connect(Socket.java:886) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at com.squareup.okhttp.internal.Platform$Android.connectSocket(Platform.java:190) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at com.squareup.okhttp.Connection.connectSocket(Connection.java:196) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at com.squareup.okhttp.Connection.connect(Connection.java:172) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at com.squareup.okhttp.Connection.connectAndSetOwner(Connection.java:367) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at com.squareup.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:128) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:328) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:245) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at com.squareup.okhttp.Call.getResponse(Call.java:267) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:224) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at com.squareup.okhttp.Call.execute(Call.java:79) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at retrofit.OkHttpCall.execute(OkHttpCall.java:116) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at retrofit.ExecutorCallAdapterFactory$ExecutorCallbackCall.execute(ExecutorCallAdapterFactory.java:61) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:230) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:114) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at com.droidmonkey.moveblue.FeedLoader.performUpdate$background(FeedLoader.groovy:75) 11-04 19:04:35.465 10315-10918/com.droidmonkey.moveblue E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)

  1. ank_07 2 times, last 4 months ago
  2. dmitry 65 times, last 6 months ago
5 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. android.system.ErrnoException

    connect failed: EHOSTUNREACH (No route to host)

    at libcore.io.Posix.connect()
  2. Android
    IoBridge.connect
    1. libcore.io.Posix.connect(Native Method)
    2. libcore.io.BlockGuardOs.connect(BlockGuardOs.java:111)
    3. libcore.io.IoBridge.connectErrno(IoBridge.java:137)
    4. libcore.io.IoBridge.connect(IoBridge.java:122)
    4 frames