Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Socket: java.net.SocketException: No route to host

I am trying to connect (through TCP) to the server running on my machine from the Android device. I have android.permission.INTERNET in my manifest file:

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

I am able to connect using emulator but trying from the device throws an error:
Android Socket: java.net.SocketException: No route to host

Can anyone please help.

like image 315
Android_enthusiast Avatar asked Oct 26 '11 16:10

Android_enthusiast


3 Answers

Disabled wifi on my Android device and then re-enabled it and it worked.

like image 192
Haris ur Rehman Avatar answered Nov 09 '22 15:11

Haris ur Rehman


Your 192.168.1.114 address is a DHCP address (dynamically) assigned by your router to your PC. As a result it is visible to the emulator.

But depending on how your WiFi is set up, the Android is probably on a different router / subnet and can't see 192.168.1.114. You could check that by typing 192.168.1.114 into the address bar of the Android browser.

If 192.168.1.114 is not visible to your Android, then you will have to either change the routing rules on your router to make it visible, or add a DNS lookup for it.

like image 26
Torid Avatar answered Nov 09 '22 15:11

Torid


I had the same problems. It turned out my Win7 firewall was blocking the connection.

like image 40
pi23 Avatar answered Nov 09 '22 15:11

pi23