开发者

Bonjour to JmDNS from iOS: What's the name?

I'm sure I'm just a few letters away from getting this to work, but maybe not...

On the server-side, I've got this (Java);

ServiceInfo info = ServiceInfo.create("_mjdj._tcp.local.", "foo", 1268, 0, 0, "path=index.html");
jmdns.registerService(info);

This works perfectly with my Java client or a Bonjour Browser (service shows as "_mjdj._tcp." in local). So in Java this works:

jmdns.list("_mjdj._tcp.local.");

But from an iOS client I can't seem to find the service (or something). I've got the delegate methods in place, but this

NSNetServiceBrowser *browser = [[[NSNetServiceBrowser alloc] init] autorelease];
[browser setDelegate:self];
[browser searchForServicesOfType:@"_mjdj._tcp.local." inDomain:@""];

produces this error

{
 NSNetServicesErrorCode = "-72004";
 NSNetServicesErrorDomain = 10;
}

and if I do this (gues开发者_StackOverflowsing)

[browser searchForServicesOfType:@"_mjdj._tcp." inDomain:@"local"];

the netServiceBrowserWillSearch gets called but nothing after that.


[browser searchForServicesOfType:@"_mjdj._tcp.local." inDomain:@""];

That's your error. You want

[browser searchForServicesOfType:@"_mjdj._tcp." inDomain:@""];

The "local." part is the domain, so you could use the domain "local." if you want, but @"" means use the default registration domains (which includes, but is not necessarily limited to, "local."). The reason you're confused is because the Java API is bad. It should not be squishing the service type and domain together like that.

Note that your attempt at using @"local" failed, most likely because you forgot the trailing period. I suggest you just use @"" though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜