JmDNS:无法解析服务 [英] JmDNS: Can't resolve service

查看:1337
本文介绍了JmDNS:无法解析服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现JmDNS发现了一个Android应用程序和桌面应用程序之间的通信。我按照下面的教程: <一href="http://home.heeere.com/tech-androidjmdns.html">http://home.heeere.com/tech-androidjmdns.html

Android应用程序注册一个服务和桌面应用程序添加了一个侦听服务。我得到它的工作完全没有用四分之三的我的设备,但与第四个(一个三星Galaxy Tab 10.1 PT7500运行的是Android 3.2)我解决不了的服务。 我的处理程序接收 serviceAdded 事件,但没有 serviceResolved 事件。 我也打过电话 jmdns.requestServiceInfo jmdns.getServiceInfo ,但前者不执行任何操作,而后者超时,返回null。

在jmdns浏览器,但是,是能够解决的服务就好了,所以它不是设备。 有没有防火墙在任一设备。服务始终使用IPv4地址。

没有任何人有一个想法是什么可能会导致这个问题?

$ C $下启动服务:

  jmdns = JmDNS.create(wifiAddress);

ServiceInfo serviceInfo = ServiceInfo.create(Constants.SERVICE_TYPE,
    Constants.SERVICE_NAME,Constants.ZEROCONF_PORT,我的服务);

HashMap的&LT;字符串,字符串&GT; deviceInfoMap =新的HashMap&LT;字符串,字符串&GT;();
deviceInfoMap.put(Constants.KEY_DEVICE_NAME,getDeviceName());
deviceInfoMap.put(Constants.KEY_DEVICE_ID,getDeviceId());
// ...
serviceInfo.setText(deviceInfoMap);

jmdns.registerService(serviceInfo);
 

code客户端/监听器:

  jmdns = JmDNS.create();
jmdns.addServiceListener(Constants.SERVICE_TYPE,的ServiceListener =新的ServiceListener(){
    @覆盖
    公共无效serviceResolved(ServiceEvent事件){
        的System.out.println(服务解决:+ event.getName()+
            类型的+ event.getType());
    }

    @覆盖
    公共无效serviceRemoved(ServiceEvent事件){
        的System.out.println(服务中删除:+ event.getName()+
            类型的+ event.getType());
    }

    @覆盖
    公共无效serviceAdded(ServiceEvent事件){
        的System.out.println(服务补充说:+ event.getName()+
            类型的+ event.getType());
        ServiceInfo信息= jmdns.getServiceInfo(event.getType(),event.getName());
        的System.out.println(服务信息:+信息); //  - &GT;空值
    }
});
 

输出:

 服务补充说:类型_mytype._tcp.local我的业务@ GT-P7500。
服务信息:空
服务补充:我的服务@类型_mytype._tcp.local的Galaxy Nexus的。
服务信息:[ServiceInfoImpl @ 183779345
    名称:我的业务@ Galaxy Nexus的._mytype._tcp.local。
    地址:'/192.168.1.154:4242状态:DNS:myhost.local。
    状态:1探测任务:空,有数据
    设备名称:Galaxy Nexus的
    DEVICEID:其中,ID&GT;
    displayDensity:XHDPI
]
 

解决方案

签出从的 SVN仓库的伎俩。发现该服务目前在所有设备上工作得很好。 (注:我是用JmDNS版本3.4.1这是我从已经下载 sourceforge上前)

通过SVN历史的经脱脂,似乎有几个犯下有关的问题,因为3.4.1释放解决服务

I'm trying to implement JmDNS discovery for communication between an Android app and a desktop application. I have followed the following tutorial: http://home.heeere.com/tech-androidjmdns.html

The Android app registers a service and the desktop application adds a listener for the service. I've got it working perfectly fine with three out of four of my devices, but with the fourth one (a Samsung Galaxy Tab 10.1 PT7500 running Android 3.2) I can't resolve the service. My handler receives the serviceAdded event, but no serviceResolved event. I have also tried calling jmdns.requestServiceInfo and jmdns.getServiceInfo, but the former does nothing and the latter times out and returns null.

The jmdns-browser, however, is able to resolve the service just fine, so it's not the device. There is no firewall on either of the devices. The service always uses an IPv4 address.

Does anybody have an idea what could cause this problem?

Code for starting the service:

jmdns = JmDNS.create(wifiAddress);

ServiceInfo serviceInfo = ServiceInfo.create(Constants.SERVICE_TYPE, 
    Constants.SERVICE_NAME, Constants.ZEROCONF_PORT, "my service");

HashMap<String, String> deviceInfoMap = new HashMap<String, String>();
deviceInfoMap.put(Constants.KEY_DEVICE_NAME, getDeviceName());
deviceInfoMap.put(Constants.KEY_DEVICE_ID, getDeviceId());
// ...
serviceInfo.setText(deviceInfoMap);

jmdns.registerService(serviceInfo);

Code for the client / listener:

jmdns = JmDNS.create();
jmdns.addServiceListener(Constants.SERVICE_TYPE, serviceListener = new ServiceListener() {
    @Override
    public void serviceResolved(ServiceEvent event) {
        System.out.println("Service resolved: " + event.getName() + 
            " of type " +    event.getType());
    }

    @Override
    public void serviceRemoved(ServiceEvent event) {
        System.out.println("Service removed: " + event.getName() + 
            " of type " + event.getType());
    }

    @Override
    public void serviceAdded(ServiceEvent event) {
        System.out.println("Service added: " + event.getName() + 
            " of type " + event.getType());
        ServiceInfo info = jmdns.getServiceInfo(event.getType(), event.getName());
        System.out.println("Service info: " + info); // --> null
    }
});

Output:

Service added: my service @ GT-P7500 of type _mytype._tcp.local.
Service info: null
Service added: my service @ Galaxy Nexus of type _mytype._tcp.local.
Service info: [ServiceInfoImpl@183779345 
    name: 'my service @ Galaxy Nexus ._mytype._tcp.local.' 
    address: '/192.168.1.154:4242 ' status: 'DNS: myhost.local. 
    state: probing 1 task: null', has data
    deviceName: Galaxy Nexus
    deviceId: <id>
    displayDensity: XHDPI
] 

解决方案

Checking out the latest source code version from the SVN repository did the trick. Discovering the service now works just fine on all devices. (Note: I was using JmDNS version 3.4.1 which I had downloaded from sourceforge before)

Having skimmed through the SVN history, there seem to be a couple of commits related to problems with resolving services since the 3.4.1 release.

这篇关于JmDNS:无法解析服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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