Android SDK Connect to Web Server on Host

穿精又带淫゛_ 提交于 2019-12-18 12:38:56

问题


I am building a web service, and an android app to utilize it. I am doing both through Eclipse. When I'm running the web server locally, I can connect from my host machine's web browser at http://localhost:8888/. How can I connect to that from my android app running on the emulator on the same machine?


回答1:


How can I connect to that from my android app running on the emulator on the same machine?

If you are referring your localhost on your system from the Android emulator then you have to use http://10.0.2.2:8888/. Because Android emulator runs inside a Virtual Machine(QEMU) therefore here 127.0.0.1 or localhost will be emulator's own loopback address.

Refer: Emulator Networking




回答2:


I think you can not connect through localhost. Try to access it though IP address. Because, emulator and Machine making a network.



来源:https://stackoverflow.com/questions/5114301/android-sdk-connect-to-web-server-on-host

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