Earlier research with Wi-Fi Direct and Dns-Sd Txt record size measurements suggested that there maximum size that is less than 1k buffer for the Dns-Sd records. With the Delivering discovery data via Wi-Fi Direct UPnP I also noted that at least with UPnP the buffer is actually shared with all apps, meaning that its actually not a limit of one service advertisement, but actually its limiting the combined size of all service advertisements active on the device.
I did quick tests and determined that, indeed this its same with the Dns-Sd records, and there also the latest added service can easily make the previously set advertisement to never actually be advertised, effectively making the service invisible for anybody looking for it.
Additionally it was earlier determined that the instance name does effect on the data amount. With my investigation I also determined that also the length of the service type string will affect the limits posed for the instance name.
As I never really did finalize the instance name limit investigation, I decided to get it done now. I was using the good old WifiTestPower app, and modified the service type to be just 10 characters long. I was using Nexus 5 devices. Two of them had KitKat (4.4.4 and 4.4.3) and two had Lollipop (5.0.1 and 5.1.0).
The result showed that the max limit is not really set by the receiver (as I earlier thought), but actually its set by the limits posed on the sending device.
With KitKat I determined that when using 10 character long Service type string, then the usable limit appears to be 100 characters.
Actually I can see 101 very often, but its causing loads of time when the service discovery after finding one service will timeout without finding anything, and as this does not appear to happen when using 100 characters long instance name, I would put the limit there.
Funnily enough, when I give the WifiP2pDnsSdServiceInfo empty txt-record array, then even when I’m not getting the DnsSdServiceResponseListener called for instance names over 101, I do get the DnsSdTxtRecordListener called with 103 characters long instance name, and indeed the fullDomainName argument is having the full instance name included.
That all said, with the current knowledge of the topic, if the service type is 10 characters long, I would still put the maximum length of the instance name to be 100 characters.
With Lollipop, if the service type is 10 characters long, the limit appears to be 255 characters limit works with both interfaces, and if exceeded no discovery data is seen to arrive either of them.
So if you want to get the discovery work with and between both KitKat and Lollipop then with 10 character long service type we could use up to 100 characters long instance names.
Note then that if we also take account the less than 1K total limit, I would assume we could safely assume that in one device we can have 6-8 services advertised before the system starts dropping them from the actual advertisement.