Android SDK中连接到主机上的Web服务器连接到、主机、服务器、Android

2023-09-05 09:51:30 作者:〆灬拿命来爱你

我建立一个Web服务,和一个Android应用程序,利用它。我通过Eclipse的这两项工作。当我在本地运行的Web服务器,我可以从我的主机的网络浏览器在 HTTP连接://本地主机:8888 / 。我怎样才能连接到从我的Andr​​oid应用程序运行在同一台机器上的仿真器?

解决方案   

我怎样才能连接到从我的Andr​​oid应用程序在同一台机器?

在模拟器上运行

如果您是从Android模拟器指本地主机系统上,那么你必须使用 http://10.0.2.2:8888/ 。由于Android模拟器在虚拟机中运行(QEMU),因此在这里 127.0.0.1 本地主机将仿真器自身的环回地址

参见:Emulator网络

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?

解决方案 Web服务器架构简单介绍

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

 
精彩推荐
图片推荐