I am trying to implement JmDNS discovery for communication between an Android application and a desktop application. I completed the following tutorial: http://home.heeere.com/tech-androidjmdns.html
The Android application registers the service, and the desktop application adds a listener to the service. It works fine for me with three of my four devices, but with the fourth (Samsung Galaxy Tab 10.1 PT7500 running Android 3.2). I can not allow this service. My handler receives the serviceAdded event, but not the serviceResolved event. I also tried calling jmdns.requestServiceInfo and jmdns.getServiceInfo , but the first one does nothing and the last time expires and returns null.
However, the jmdns browser is able to enable the service just fine, so this is not a device. There is no firewall on any of these devices. A service always uses an IPv4 address.
Does anyone have any ideas what might cause this problem?
Code to start 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());
Code for 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);
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 ]
Algorithm and Blues
source share