• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSNetServiceBrowser
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: NSNetServiceBrowser
      • From: Lloyd Dupont <email@hidden>
References: 
 >NSNetServiceBrowser (From: Lloyd Dupont <email@hidden>)

  • Prev by Date: Re: NSNetServiceBrowser
  • Next by Date: Re: NSNetServiceBrowser
  • Previous by thread: Re: NSNetServiceBrowser
  • Next by thread: Re: NSNetServiceBrowser
  • Index(es):
    • Date
    • Thread