Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

no route to host

I wrote an app on my phone with Android. I'm debugging it on phone. I try to connect to a server written in C#, but every time I try to connect, I have exception:

EHOSTUNREACH (No route to host)

I add to manifest:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

My code to connect:

try {
        InetAddress serverAddr = InetAddress.getByName(IP);
        int PortI = Integer.parseInt(Port);
        socket = new Socket(serverAddr, PortI);
}
like image 203
marczak Avatar asked Jan 28 '13 16:01

marczak


1 Answers

Try this!

  1. Check your device is connected with internet which make request to server and on same network when testing in LAN network.

  2. Check you have disabled the firewall of server if you are connected in LAN.

  3. Check the URL where you are sending request.

like image 107
Ajay S Avatar answered Sep 19 '22 17:09

Ajay S