gethostbyname 失败并出现错误 111 (ECONNREFUSED)
该设备具有网络连接(WiFi 和 3G)。
调用 gethostbyname() 返回 NULL 和 errno 111 (ECONNREFUSED)。
相同的调用在 osx 和 windows 上运行良好。
可能是什么问题?
最好的,
The device does have network connectivity (WiFi and 3G).
Calling gethostbyname() returns NULL with errno 111 (ECONNREFUSED).
The same call works fine on osx and windows.
What could be the problem?
Best,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该在 AndroidManifest.xml 中添加使用互联网的权限:
You should add permission to use Internet in your AndroidManifest.xml:
问题很可能是您设备上的 DNS 服务器设置未配置或配置错误。请务必检查一下。这很可能是您本地 WiFi 网络的问题 - 可能没有本地 DNS 服务器。
也许您也可以尝试禁用 WiFi,因为 DNS 解析应该在您的移动网络中自动工作。
The problem is most likely a not or wrong configured DNS server setting on your device. Be sure to check that. This is most probably a problem with your local WiFi network - probably there's no local DNS server.
Maybe you could also try disabling WiFi as DNS resolution should work automatically in your mobile network.
ECONNREFUSED
表明您设备上的 DNS 解析器可能尝试故障转移到 TCP/IP(而不是 UDP),因为答案太长,无法适应正常的 UDP 响应包。如果配置的 DNS 服务器不支持通过 TCP 的入站 DNS 请求,您将收到该错误。
客户端应用程序通常无法从 UDP 套接字获取
ECONNREFUSED
,因为它们是无状态的。ECONNREFUSED
suggests that the DNS resolver on your device may have tried failing over to TCP/IP (instead of UDP) because the answer was too long to fit in a normal UDP response packet.If the configured DNS servers don't support inbound DNS requests over TCP you'd get that error.
Client apps can't normally get
ECONNREFUSED
from a UDP socket because they're stateless.