1

I'm trying to implement JMDNS in an Android app. Here's the relevant code:

...

jmDNS = JmDNS.create(myaddr);
HashMap props= new HashMap();
props.put(PROP_USER_NAME,userName);
props.put(PROP_USER_ID,userId);
ServiceInfo serviceInfo  =  ServiceInfo.create(SERVICE_TYPE,originalServiceName,port,0,0,true,props);

jmDNS.registerService(serviceInfo);
jmDNS.addServiceListener(SERVICE_TYPE, mdnsServiceListener = new ServiceListener()  {

        public void serviceAdded (ServiceEvent serviceEvent){


          jmDNS.requestServiceInfo(serviceEvent.getType(), serviceEvent.getName(), true);

        }

    public void serviceRemoved (ServiceEvent serviceEvent){

        Log.i(TAG, "A service was removed");
        //Log.i(TAG,"NAME "+serviceEvent.getInfo().getPropertyString(PROP_USER_ID) + serviceEvent.getInfo().getPropertyString(PROP_USER_NAME));
        // Test service is disappeared.
    }

    public void serviceResolved (ServiceEvent serviceEvent){
        // Test service info is resolved.
        Log.i(TAG, "A service was resolved");
        ServiceInfo serviceInfo = serviceEvent.getInfo();
            Log.i(TAG, "NAME" + serviceInfo.getName());
            Log.i(TAG, "user_name" + serviceInfo.getPropertyString(PROP_USER_NAME));


    }

    });

So far, I'm running into several issues:

  1. Service discovery by other devices is not consistent. Sometimes discovery works, sometimes it doesn't. Sometimes it works at first but stops after a while.
  2. Receiving updated txt record information is also very inconsistent. This is very recurrent. The process to update the TXT in a service is the following is:

    jmDNS.unregisterAllServices();
    jmDNS.removeServiceListener(SERVICE_TYPE, mdnsServiceListener);
    

And then i start the registration process all over again. The problem is that other devices detect the new service with serviceResolved but the txt record is still outdated.

Roberto Betancourt
  • 2,375
  • 3
  • 27
  • 35

0 Answers0