Re: [Bonjour] Any mechanism to deal with Aurevoir and re-bonjour?
Re: [Bonjour] Any mechanism to deal with Aurevoir and re-bonjour?
- Subject: Re: [Bonjour] Any mechanism to deal with Aurevoir and re-bonjour?
- From: Stephane Sudre <email@hidden>
- Date: Thu, 21 Feb 2008 11:24:00 +0100
On 20 févr. 08, at 16:56, Michael Ledford wrote:
Hi Stephane,
A few things you might check...
1) You have set a delegate for the NSNetServiceBrowser instance you
have created.
Yes.
2) The delegate you have set indeed implements the delegate method
with the correct method signature.
AFAIK, yes.
2) You have done a search for services using the instance created and
have not sent the stop message to the instance.
Yes.
3) Your code is in a run-loop.
That's a good question. I don't do anything to add the
NSNetServiceBrowser to a run-loop. I assume from the documentation that
it's automatically added to the current run-loop and that you can
remove it or move it to another run-loop if needed.
The test I'm doing is the following one:
1. Search for _workstation._tcp.
2. Wait for the results
3. Connect to a remote Mac using ARD.
4. Change the IP of the Mac. (Quit ARD).
5. Wait for anything to happen in the sample code.
@implementation MainController
- (void) awakeFromNib
{
sharedServiceBrowser_=[[NSNetServiceBrowser alloc] init];
if (sharedServiceBrowser_!=nil)
{
[sharedServiceBrowser_ setDelegate:self];
[sharedServiceBrowser_ searchForServicesOfType:@"_workstation._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(@"not failure");
}
- (void)netServiceBrowser:(NSNetServiceBrowser *) inNetServiceBrowser
didFindService:(NSNetService *) inNetService
moreComing:(BOOL)moreComing
{
[inNetService retain];
[inNetService setDelegate:self];
[inNetService resolveWithTimeout:120.0];
}
- (void)netServiceBrowser:(NSNetServiceBrowser *) inServiceBrowser
didRemoveService:(NSNetService *) inService moreComing:(BOOL)moreComing
{
NSLog(@"netServiceBrowser:didRemoveService:");
}
@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