javaandroidbonjourairplayjmdns

JmDNS TXT Field with multiple parameters


I am using JmDNS to simulate an Bonjour Service / AirPlay.

ServiceInfo info = ServiceInfo.create(
            "test@AppleTV._airplay._tcp.local",
            "test@AppleTV", 46667, "deviceid=00:11:7F:54:DF:0B features=0x2a7f model=AndroidTV2,1 srcvers=130.14");

JmmDNS dns = JmmDNS.Factory.getInstance();
try {
    ((JmmDNSImpl) dns).inetAddressAdded(new NetworkTopologyEventImpl(
                JmDNS.create(InetAddress.getByName("localhost")),
                InetAddress.getByName("localhost")));
    dns.registerService(info);
    Thread.sleep(1000); // If this isn't done the Announcement sometimes
                            // doesn't go out on the local interface
} catch (Exception e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}

The iPhone doesn't see my device, so I checked the mDNS logs on my MBPR. Result

(1) Working service

_airplay._tcp                                   PTR     ITV@139._airplay._tcp
ITV@139._airplay._tcp                           SRV     0 0 46667 localhost.local. ; Replace with unicast FQDN of target host
ITV@139._airplay._tcp                           TXT     "deviceid=00:11:7F:54:DF:0B" "features=0x2a7f" "model=AndroidTV2,1" "srcvers=130.14"

(2) my non working service

_airplay._tcp                                   PTR     test@AppleTV._airplay._tcp
test@AppleTV._airplay._tcp                      SRV     0 0 46667 android-3e71c0c088c7a603.local. ; Replace with unicast FQDN of target host
test@AppleTV._airplay._tcp                      TXT     "eviceid=00:11:7F:54:DF:0B features=0x2a7f model=AndroidTV2,1 srcvers=130.14"

As you can see the fist char is being cut off. If I add \" before each kv-pair it gives a really weird result. So how can I get the same result as if in (1)?

Thanks!


Solution

  • Got it:

    Map<String, String> map = new HashMap<String, String>();
        map.put("deviceid", "00:11:7F:54:DF:0B");
        map.put("features", "0x2a7f");
        map.put("model", "AndroidTV2,1");
        map.put("srcvers", "130.14");
        ServiceInfo info = ServiceInfo.create(
                "tt@AppleTV._airplay._tcp.local",
                "tt@AppleTV", 46667,1,1,false, map);