我正在尝试在iOS设备上初始化JmDNS,使用以下行获取地址:
InetAddress adr = InetAddress.getLocalHost();
它在iphone模拟器中工作正常,但是当在物理iOS设备上测试时,这会导致带有stacktrace的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有关,但我不完全确定。也许有人可以对此有所了解?
答案 0 :(得分:0)
自己想出来。显然,iOS会阻止您通过getLocalHost获取本地IP地址。我不得不使用RoboVM桥来插入Objective-C脚本来执行此操作:http://blog.robovm.org/2013/08/support-for-objective-c-blocks.html