Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

RossOliver

macrumors regular
Original poster
Nov 6, 2006
157
0
Hey,

I create an NSNetService:

Code:
service = [[NSNetService alloc] initWithDomain:@"" type:@"_myprog._tcp" name:@"My Prog Server" port:28496];
		[service setDelegate:self];

Which works fine, then in the client side I browse for the service and in the delegate method:

Code:
-( void )netServiceBrowser:( NSNetServiceBrowser * )netServiceBrowser 
			didFindService:( NSNetService * )netService moreComing:( BOOL )moreComing
{
	printf( "desc: %s, name: %s, host: %s, port: %i\n", [[netService description] UTF8String], [[netService name] UTF8String], [[netService hostName] UTF8String], [netService port] );
}

It seems to descover the service perfectly, but for some reason thinks the host name is null and the port is 0 instead of 28496:

desc: <NSNetService 0x44d800> local. _myprog._tcp. My Prog Server, name: My Prog Server, host: (null), port: 0

Any ideas why this would happen?

Thanks for your time,

-Ross
 

RossOliver

macrumors regular
Original poster
Nov 6, 2006
157
0
I read that I need to resolve the host and port with resolveWithTimeout: so I added this to the method when a service is found:

Code:
[netService setDelegate:self];
[netService resolveWithTimeout:5];

I implemented netService:didNotResolve: and netserviceDidResolveAddress: but they don't appear to be called at all :confused:


I also notice that the [netService addresses] returns an empty array...

-Ross
 

RossOliver

macrumors regular
Original poster
Nov 6, 2006
157
0
You are retaining the incoming service? That might do the trick, i put them in one array in my application.


Manty

At the moment I'm not - I will give that a try. I also read in the documentation that I have to use initWithDomain@"local." instead of @"" for the resolution process to work, so I will give that a go too...

Thanks for the suggestion
 

RossOliver

macrumors regular
Original poster
Nov 6, 2006
157
0
You are retaining the incoming service? That might do the trick, i put them in one array in my application.


Manty

You were spot on - I had to retain the service. It must have been discarded at the end of the method, which makes sense since it's an automatic variable :rolleyes:

Cheers
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.