Re: NSNetServiceBrowser
Re: NSNetServiceBrowser
- Subject: Re: NSNetServiceBrowser
- From: j o a r <email@hidden>
- Date: Wed, 7 May 2003 07:29:51 +0200
If you have used a NSNetServiceBrowser to find a NSNetService, you
should be able to do something like this to get hold of the address
(and port) of the resolved net service:
+ (NSString *) addressFromService:(NSNetService *) service
{
NSString *addressStr = nil;
NSData *aData = [[service addresses] lastObject]; // Note: Discards
all but one address
if (aData != nil)
{
struct sockaddr_in addrIn = *(struct sockaddr_in *)[aData bytes];
// NSLog(@"Port: %d", addrIn.sin_port);
addressStr = [NSString stringWithFormat: @"%s",
inet_ntoa(addrIn.sin_addr)];
}
return addressStr;
}
j o a r
On Wednesday, May 7, 2003, at 06:33 Europe/Stockholm, Lloyd Dupont
wrote:
I have a simple service which runs on all ours computers as a startup
items. I communicate to them through DO (using NSSocketPort) now, I
try to advertise them with Rendezvous to have a (magic) "zero
configuration" access to each of them.
My concern is while I am able to get NSNetServiceBrowser to get them
(the delegate method
- (void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser
didFindService:(NSNetService *)aNetService
moreComing:(BOOL)moreComing
return me all services
)
I'm unable to get the port and host information from the NSNetService
(which is crucial to properly initialize NSSocketPort), although I
correctly initialize my NSNetService with this initializer:
NSNetService * myService = [[NSNetService alloc]
initWithDomain:@""
type:@"_myProtocol._tcp."
name:@"my service"
port:MY_PORT];
I can't get its host and port.
any idea ? tips ? links ?
_______________________________________________
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.