无法从Android设备访问本地主机 [英] Cannot access localhost from Android device

查看:123
本文介绍了无法从Android设备访问本地主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仿真器可以访问Web服务fromlocal主机上,但我真正的设备无法虽然我使用LAN IP地址,而不是10.0.2.2(192.168.xx.yyy)。当然,我的Andr​​oid手机是由亚洲开发银行的认可,并通过USB端口连接我的笔记本电脑。

Emulator can access web service fromlocal host but my real device cannot although I use LAN ip address (192.168.xx.yyy) instead of 10.0.2.2. Of course, my android mobile was recognized by adb and it connected my laptop via usb port.

我已经阅读计算器一些类似的问题,但仍然不知道如何从一个真正的Andr​​oid手机访问web服务。这个问题的答案<一href="http://stackoverflow.com/questions/4779963/how-can-i-access-my-localhost-from-my-android-device">How我可以访问我的本地主机从我的Andr​​oid设备?我是有用的,但我真的不明白的答案。

I already read some similar questions at stackoverflow but still didn't know how to access webservice from a real android mobile. The answer of this question How can i access my localhost from my android device? my be useful but i don't really understand that answer.

任何人都可以帮助我吗?谢谢您!

Anyone helps me? Thanks you!

推荐答案

可能是Web服务器监听loopback接口,但没有网络接口。这意味着,在 127.0.0.1 命中和本地主机的工作,但 192.168.xxx。 XXX 不会(无论是从本地主机,局域网,广域网或)。

Possibly the web server is listening on the loopback interface but not on the network interface. This means that hits on 127.0.0.1 and localhost will work, but 192.168.xxx.xxx will not (whether from localhost, LAN, or WAN).

要确定哪个接口服务器监听,看<一href="http://www.commandlinefu.com/commands/view/702/lists-all-listening-ports-together-with-the-pid-of-the-associated-process#comment"相对=nofollow>此处命令给大家介绍一下侦听端口(我用 lsof的-PAN -i TCP -i UDP )。然后寻找在列表中的服务器进程。对于 lsof的命令,如果8888端口,你看到类似 TCP *:8888(LISTEN)那么你的服务器侦听所有接口。但如果你看到类似 TCP [::127.0.0.1]:8888(LISTEN)那么你已经确定你的问题!

To determine which interface the server is listening on, look here for a command to tell you about the listening ports (I used lsof -Pan -i tcp -i udp). Then look for your server process in the list. For the lsof command, if for port 8888 you see something like TCP *:8888 (LISTEN) then your server is listening on all interfaces. But if you instead see something like TCP [::127.0.0.1]:8888 (LISTEN) then you have identified your problem!

下一步解决你的问题是设置服务器的运行配置为侦听所有接口。我不知道你的服务器使用,但如果你可以指定一个IP地址,那么你可能想尝试 0.0.0.0 。通常你可以做到这一点接近它允许您指定的侦听端口。因此,如果你有这样的配置:

The next step to solve your problem is to set up your server's run configuration to listen on all interfaces. I don't know what server you are using, but if you can specify an IP address, then you may want to try 0.0.0.0. Usually you can do this near where it lets you specify the listening port. Thus, if you have a configuration like:

- 8888端口

那你可以试试:

- 8888端口--address 0.0.0.0

这篇关于无法从Android设备访问本地主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆