views:

65

answers:

1

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 (guessing)

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

the netServiceBrowserWillSearch gets called but nothing after that.

+1  A: 
[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.

Kevin Ballard
Hi Kevin and thanks muchly for your answer. I've now tried with the recommended blank `inDomain` and `_mjdj._tcp.` and none of the delegate methods are firing beyond `netServiceBrowserWillSearch`... perhaps it's the iPhone simulator that I'm running inside? Though it does connect to sockets on the Java side with no problems.
Yar
Just tried on "the device" (iPod) and it didn't work either. Hmmmm... maybe I should try a straight Mac app next.
Yar
If you're willing to spend $3 to help debug this issue, I have a version of Bonjour Browser written for the iPhone. It's called [Discovery](http://itunes.apple.com/us/app/discovery-bonjour-browser/id305441017?mt=8), and you can use it to see if your service is visible on the device.
Kevin Ballard
I'm game, but I'll bet another $3 that you can see the service from the device. Here goes...
Yar
Yep, it sees it. But it's showing up as "_mjdj._tcp." and then the service is called "foo"... checking my code for clues.
Yar
Okay, got it... I was autoreleasing my browser instance... that was dumb. Thanks!
Yar
Hah, yep, that would do it. Make sure you're holding it around in an ivar so you can release it later when you're actually done with it.
Kevin Ballard
Cool, thanks again for your help, I'm sure the browser will come in handy again.
Yar
Do let me know if you have any feature requests for Discovery. As for Bonjour Browser itself, you can send requests, but I've been meaning to rewrite it for about 4 years now, so don't expect me to move very fast ;)
Kevin Ballard