我正在尝试在 iOS 设备上初始化 JmDNS,使用以下行获取地址:
InetAddress adr = InetAddress.getLocalHost();
它在 iphone 模拟器中运行良好,但是在物理 iOS 设备上进行测试时,这会导致 UnknownHostException,并带有堆栈跟踪:
java.net.UnknownHostException: Unable to resolve host "#{name of iphone}": nodename nor servname provided, or not known
at libcore.io.GaiException.rethrowAsUnknownHostException(GaiException.java)
at java.net.InetAddress.lookupHostByName(InetAddress.java)
at java.net.InetAddress.getLocalHost(InetAddress.java)
at com.glassknuckle.ThiefTown.Networking.ThiefClient$NETWORK_TASK.run(ThiefClient.java)
at java.lang.Thread.run(Thread.java)
Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NONAME (nodename nor servname provided, or not known)
at libcore.io.Posix.getaddrinfo(Native Method)
at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java)
... 4 more
我读过建议将“127.0.0.1”作为地址传递,但是当其他设备试图通过该 IP 连接到它时,这不起作用。我不确定从这里做什么——我肯定需要获取本地 IP 地址,但我不知道如何获取它。这似乎与 roboVM 有关,但我不完全确定。也许有人可以对此有所了解?