I am currently working with MYNetwork library Bonjour classes and have a problem discovering txt records. When a new service appears it's txt record is null every time.
On my server side I setup txt record this way:
self.server = [[MYBonjourRegistration alloc] initWithServiceType: @"_blipecho._tcp." port:9121];
[server setString:@"Cyprian" forTXTKey:@"Name"];
[server start];
Then on the Browser I discover and log the data:
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
if ([keyPath isEqual:@"services"]) {
NSSet *newServices = (NSSet*)[change objectForKey:@"new"];
if(newServices){
MYBonjourService *service;
for (service in newServices){
textView.text = [NSString stringWithFormat:@"%@\nNew user: %@ (%@)", textView.text, service.name, [service txtRecord]];
}
}
}
And I get null for the txtRecord.
Ok, got the answer.
The problem was that the newly discovered service is was no yet resolved hence there was no data.
Had to resolve the service first.
-(void)resolveService:(MYBonjourService*)service{
service.addressLookup.continuous = YES;
[service.addressLookup addObserver: self
forKeyPath: @"addresses"
options: NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew
context: NULL];
[service queryForRecord: kDNSServiceType_NULL];
}