Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 17, 2008, 04:18 PM   #1
RossOliver
macrumors regular
 
Join Date: Nov 2006
NSNetService works, but hostName is null and port is 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:

Quote:
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 is offline   0 Reply With Quote
Old Jul 18, 2008, 02:09 AM   #2
RossOliver
Thread Starter
macrumors regular
 
Join Date: Nov 2006
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


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

-Ross
RossOliver is offline   0 Reply With Quote
Old Jul 18, 2008, 03:52 AM   #3
Manty
macrumors member
 
Join Date: Mar 2008
Location: Lisbon, Portugal
You are retaining the incoming service? That might do the trick, i put them in one array in my application.


Manty
__________________
Work: iMac, 2.0 GHz, 2 GB RAM, 250 GB HD;
Home: MacBook White 2.2 GHz, 4 GB RAM, 250GB HD; 8GB iPhone 3G
Manty is offline   0 Reply With Quote
Old Jul 18, 2008, 03:56 AM   #4
RossOliver
Thread Starter
macrumors regular
 
Join Date: Nov 2006
Quote:
Originally Posted by Manty View Post
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 is offline   0 Reply With Quote
Old Jul 18, 2008, 02:16 PM   #5
RossOliver
Thread Starter
macrumors regular
 
Join Date: Nov 2006
Quote:
Originally Posted by Manty View Post
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

Cheers
RossOliver is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
My iMac's local hostname changed automatically? RedCroissant Mac OS X 10.7 Lion 6 Feb 23, 2014 04:30 PM
How can I set a hostname for my iPhone 5? ahmadka iPhone Tips, Help and Troubleshooting 4 Feb 22, 2013 01:12 PM
How does Time Machine deal with hostname change toiday OS X 0 Sep 20, 2012 01:53 PM
Hostname keeps changing bbasra OS X 10.8 Mountain Lion 1 Aug 9, 2012 09:45 PM
Hostname weirdness j-a-x Mac OS X 10.7 Lion 0 Jun 21, 2012 07:06 PM

Forum Jump

All times are GMT -5. The time now is 11:22 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC