Re: NSNetService, IP address and port number
Re: NSNetService, IP address and port number
- Subject: Re: NSNetService, IP address and port number
- From: Chris Parker <email@hidden>
- Date: Thu, 16 Jan 2003 14:25:55 -0800
Hi there -
On Thursday, January 16, 2003, at 1:16 PM, kubernan wrote:
I want to use RendezVous and i try to catch
IP address and port number inside this method :
- (void) netServiceBrowser: (NSNetServiceBrowser *) aNetServiceBrowser
didFindService: (NSNetService *) aNetService moreComing: (BOOL)
moreComing
I think i have to use something like [aNetService adresses] and read
the returned array,
but i don't know how to use the NSData item of the array with the
sockaddr structure
for reading the ip address and port number.
Can you help me ?
The example code in /Developer/Examples/PictureSharingBrowser is likely
to be helpful. You need to resolve the received NSNetService. Once it
has resolved, you can ask it for its addresses - or, since you know
that it's resolved successfully grab the first address in the list:
NSData * address = [[someNetServiceInstance addresses]
objectAtIndex:0];
The docs say that each element of the array returned by -[NSNetService
addresses] is a struct sockaddr_in suitable for use with the socket
APIs:
struct sockaddr_in *socketAddress = (struct sockaddr_in *)[address
bytes];
The rest of the code demonstrates a way to get the IPv4 address out of
this. The port is available from socketAddress->sin_port.
Note that the PictureSharing (server-side) example has a crashing bug -
comment out line 169 in PicSharingController.m (yes, there's a new
version of this forthcoming).
.chris
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.