title: NsdManager doesn't resolve multiple discovered services
body: <p>Starting with the example <a href="http://developer.android.com/training/connect-devices-wirelessly/nsd.html" rel="nofollow">http://developer.android.com/training/connect-devices-wirelessly/nsd.html</a> code, I've been building up an app meant to run on multiple devices in the same subnet. Each device registers the same service and tries to discover the others in the subnet with that service. As described in the doc, each time a device registers a service, the name gets mangled with an appended "(N)" where N is an integer. Each device, when it does a discovery ala</p>
  
  <pre><code>public void discoverServices() {
    mNsdManager.discoverServices(
        SERVICE_TYPE, NsdManager.PROTOCOL_DNS_SD, mDiscoveryListener);
  }
  </code></pre>
  
  <p>finds all the services registered. I track them in a hashmap which retains the discovered <code>NsdServiceInfo</code> record.</p>
  
  <p>The problem comes when I try to resolve them. If I iterate the hashmap and resolve each <code>NsdServiceInfo</code>, only the very first one is successful. I thought that maybe the problem is that a separate <code>NsdManager.ResolveListener</code> is needed, so I create one for each <code>NsdServiceInfo</code> record, but no joy.</p>
  
  <p>If I block the first service in the hashmap from being resolved, the next one works. Here is DDMS output:</p>
  
  <pre><code>07-09 17:11:36.799: D/P2PServiceManager(1958): Resolving services with type : PeerDiscovery
  07-09 17:11:36.799: W/P2PServiceManager(1958): Resolving PeerDiscovery services with name : PeerDiscovery (3)
  07-09 17:11:36.799: W/P2PServiceManager(1958): Resolving PeerDiscovery services with name : PeerDiscovery (2)
  07-09 17:11:36.807: E/P2PServiceManager(1958): RRRRRRRRRRRRRRRRRRR Resolve failed : error code 3
  07-09 17:11:36.830: E/P2PServiceManager(1958): RRRRRRRRRRRRRRRRRRR  Resolve Succeeded. name: PeerDiscovery\032(3)type: ._http._udphost: /192.168.1.145port: 53221txtRecord: null
  </code></pre>
  
  <p>I suspect there is some non-reentrant code or some other similar problem, but am wondering if anyone else has seen this problem. Google and StackOverflow don't seem to have the answer.</p>
  
  <p>[2014-07-24] In the end I stuck with iterating over the discovered services to resolve them, but wait for each result before resolving the next service. I suppose that is the proper way to do things, but it's not clear from the NsdManager doc one way or the other.</p>