[英]Can't access localhost from Android Emulator, but on Simulator it's working
Hope anyone can help.希望任何人都可以提供帮助。
Why I can't access localhost (10.0.2.2) from Android Emulator, but when accessing from Simulator it's working.为什么我无法从 Android Emulator 访问 localhost (10.0.2.2),但是从 Simulator 访问时它正在工作。
I was try to edit server configuration as noticed from many tutorials, but still not working.我试图编辑许多教程中注意到的服务器配置,但仍然无法正常工作。
Here the screenshots.这里是截图。
Use a port number along with IP使用端口号和 IP
http:// 10.0.2.2:8080
http://10.0.2.2:8080
Works perfect !工作完美!
or或者
you can use IP of your pc which you can get by typing ifconfig
in terminal.你可以使用你的电脑的 IP,你可以通过在终端中输入
ifconfig
来获得。 Something like就像是
I have found the solution for my problem.我已经找到了解决我的问题的方法。
I try to change the port, so it working fine.我尝试更改端口,所以它工作正常。
adb reverse tcp:8000 tcp:8000
And now I can access my computer localhost on Android with accessing localhost:8000.现在我可以通过访问 localhost:8000 在 Android 上访问我的计算机本地主机。
I just got the same problem and the reason of why I could not connect to my machine was the setting of the emulator.我刚刚遇到了同样的问题,无法连接到我的机器的原因是模拟器的设置。
How to solve:怎么解决:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.