android mdns开发实例,android resolve .local (mDNS)
android mdns开发实例,android resolve .local (mDNS)
问题
I'm looking for a solution to resolve .local host names with Android 4.0.4 (no NSD, due to API level 15). On the device I don't have any service to discover, just the hostname.
Could you please provide an example how to resolve? I integrated the jmDNS, but don't know how to use for host name resolving.
win-cmd:
ping kcmeasurement.local
Pinging kcmeasurement.local [10.202.0.29] with 32 bytes of data:
Reply from 10.202.0.29: bytes=32 time<1ms TTL=64
...
Thank you,
Daniel
回答1:
I had almost the same requirements as your question, apart from the requirement to use jmDNS, so I solved it with NSD. I realize this doesn't address your question exactly, but thought it might still be somewhat helpful for yourself and others to see how I solved it.
I setup an NSD discovery listener and an NSD resolve listener, and within the discovery listener code, added a filter for the target host name (e.g. "kcmeasurement", or in my case, "garagedoor").
There is a blog post here which explains in detail how to do that. Refer to steps 3-4, which are dealing with the Android App code required.
.html
For your case, I would imagine you would have to do the equivalent process but just using the jmDNS library instead of NSD.
回答2:
You should be able to use the InetAddress class to resolve the hostname for a given IP address. For example, using the IP address provided in the original question, try the following:
try
{
String hostname = InetAddress.getByName("10.202.0.29").getHostName();
}
catch (UnknownHostException e)
{
Log.e("MyApplication", "Attempt to resolve host name failed");
}
Since this is a network operation, make sure that it is not performed on the UI thread.
EDIT
You should be able to resolve a local hostname with jmDNS as follows:
InetAddress localHost = InetAddress.getByName("10.202.0.29");
JmDNS jmdns = JmDNS.create(localHost);
String localHostName = jmdns.getHostName();
来源:
- 在php中调用接口以及编写接口
- ROS1云课→29如何借助导航实现走迷宫机器人
- 卷积神经网络中特征图大小计算公式总结
- matlab多元回归分析怎么计算,matlab在多元线性回归分析中的相关计算
- java.lang.NullPointerException: null的错误
- uniapp权限(Android权限)
- componentDidMount,react
- GridView选中状态
- LruCache的终极解析
- .NET 反编译工具
- html怎么多行超出省略号,css+js 如何实现多行文字超出显示省略号(需要同时兼容ie chrome等浏览器)...
- 修改HTK代码,让其支持中文
- 更加简便的使用VSS
- VSS详解
- ext2ext3 结构分析
- VC知识库的一篇文章
- pgpool分析二
- 统计学,机器学习,数据挖掘,深度学习
- linux查看tomcat 控制台,linux 下查看Tomcat的状态,以及开启停止服务命令
- php实现远程下载文件到本地服务器指定目录