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

我只是一个虾纸丫 提交于 2019-12-01 16:12:57

问题


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.


回答1:


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




回答2:


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.




回答3:


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




回答4:


I was having the same issue with my android app running IP address of the computer. The app was working good and then suddenly volley started throwing exceptions. I tried enabling and disabling my mobile wifi and it didn't work. Then I tried shutting down my main router and turning back on. And just like that volley was happy and the app started working again:)

Hope that helps.



来源:https://stackoverflow.com/questions/7905505/android-socket-java-net-socketexception-no-route-to-host

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!