• 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: [Bonjour/Rendezvous] How to resolve a service?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bonjour/Rendezvous] How to resolve a service?


  • Subject: Re: [Bonjour/Rendezvous] How to resolve a service?
  • From: Marc Krochmal <email@hidden>
  • Date: Sat, 21 Apr 2007 12:53:18 -0700

Hi Stephane,

In case you never figured this out, you need to retain the inNetService in your didFindService before resolving it and then stop/ release it when you've finished resolving.


- (void)netServiceBrowser:(NSNetServiceBrowser *) inNetServiceBrowser didFindService:(NSNetService *) inNetService moreComing:(BOOL)moreComing
{
[inNetService setDelegate:self];

[inNetService resolveWithTimeout:120.0];
}


Best Regards,

-Marc






On Apr 5, 2007, at 9:16 AM, Stephane wrote:


On Apr 5, 2007, at 5:51 , Nathan Duran wrote:

In such as case, when - [NSNetService resolveWithTimeOut:] is called,
the resolution starts (confirmed by netServiceWillResolve:) but
returns nothing: neither a success nor a failure.

Well resolveWithTimeout has a void return type, so I wouldn't expect it to
return anything, and the documentation states that:


"If the resolve succeeds before the timeout period lapses, the receiver
sends netServiceDidResolveAddress: to the delegate. Otherwise, the receiver
sends netService:didNotResolve: to the delegate."


If you follow up with the documentation for netServiceWillResolve which
you're using, you'll find that this message is sent regardless of whether or
not resolution succeeds:


"Resolution of the service proceeds asynchronously and may still generate a
call to the delegate’s netService:didNotResolve: method if an error occurs."


I haven't tried doing the same thing you're trying to do, but I would
strongly recommend Stuart Cheshire's O'Reilly book "Zero Configuration
Networking" if you're interested in learning the ins and outs of Bonjour
programming.

I do agree with you since this is already what I'm doing (this is also why I said it was working in most cases).


Yet the fact remains that while this is working fine for most services that have the name of the computer set for the name field (e.g. "_ssh._tcp."), it does not work when dealing with other types of services that do not set the name of a computer for the name field (e.g. "_apple-sasl._tcp."). So there must be something different to do in such cases...

--------8<-------------8<-------------8<-------------8<-------------8< -------------8<-------------8<-------------

#import "MainController.h"

#include <netinet/in.h>
#include <netdb.h>

@implementation MainController

- (void) awakeFromNib
{
sharedServiceBrowser_=[[NSNetServiceBrowser alloc] init];

if (sharedServiceBrowser_!=nil)
{
[sharedServiceBrowser_ setDelegate:self];

[sharedServiceBrowser_ searchForServicesOfType:@"_apple- sasl._tcp." inDomain:@""];
}
}


#pragma mark -

- (void) printInformationForService:(NSNetService *) inNetService
{
	NSArray * tAddresses;
	NSData * tData;

	NSLog(@"Domain: %@",[inNetService domain]);

	NSLog(@"Type: %@",[inNetService type]);

	NSLog(@"Name: %@",[inNetService name]);

	NSLog(@"hostName: %@",[inNetService hostName]);

tAddresses=[inNetService addresses];

if (tAddresses!=nil)
{
NSEnumerator * tEnumerator;

tEnumerator=[tAddresses objectEnumerator];

if (tEnumerator!=nil)
{
NSData * tData;

while (tData=[tEnumerator nextObject])
{
struct sockaddr * tSockAddress;

tSockAddress = (struct sockaddr *) [tData bytes];

if (tSockAddress!=nil)
{
unsigned short tDestinationPort;

char tCIPAddress[INET6_ADDRSTRLEN];

if (tSockAddress->sa_family==AF_INET6)
{
struct sockaddr_in6 * to6;

to6=(struct sockaddr_in6 *) tSockAddress;

tDestinationPort=ntohs(to6->sin6_port);
}
else if (tSockAddress->sa_family==AF_INET)
{
struct sockaddr_in * to4;

to4=(struct sockaddr_in *) tSockAddress;

tDestinationPort=ntohs(to4->sin_port);
}

if (getnameinfo(tSockAddress, tSockAddress->sa_len, tCIPAddress, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST)==0)
{
NSString * tString;

tString=[NSString stringWithUTF8String:tCIPAddress];

if (tString!=nil)
{
NSLog(@"Address: %@:%hu",tString,tDestinationPort);
}
}
}
}
}
}

tData=[inNetService TXTRecordData];

if (tData!=nil)
{
NSLog(@"TXT Data: %@",[NSNetService dictionaryFromTXTRecordData:tData]);
}
else
{
NSLog(@"TXT Data: nil");
}
}


- (void) netServiceDidResolveAddress:(NSNetService *) inNetService
{
	NSLog(@"success");

	[self printInformationForService:inNetService];
}

- (void)netServiceWillResolve:(NSNetService *)sender
{
	NSLog(@"start");
}

- (void)netService:(NSNetService *) inNetService didNotResolve: (NSDictionary *)errorDict
{
NSLog(@"failure");
}


- (void)netServiceBrowser:(NSNetServiceBrowser *) inNetServiceBrowser didFindService:(NSNetService *) inNetService moreComing:(BOOL)moreComing
{
[inNetService setDelegate:self];

[inNetService resolveWithTimeout:120.0];
}


- (void)netServiceBrowser:(NSNetServiceBrowser *) inServiceBrowser didRemoveService:(NSNetService *) inService moreComing:(BOOL) moreComing
{


}

@end _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Macnetworkprog mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: [Bonjour/Rendezvous] How to resolve a service?
      • From: Stephane Sudre <email@hidden>
References: 
 >Re: [Bonjour/Rendezvous] How to resolve a service? (From: Stephane <email@hidden>)

  • Prev by Date: Doubt on calling IFNET_INPUT
  • Next by Date: Open Directory Authentication Using JNDI
  • Previous by thread: Re: [Bonjour/Rendezvous] How to resolve a service?
  • Next by thread: Re: [Bonjour/Rendezvous] How to resolve a service?
  • Index(es):
    • Date
    • Thread