使用 MYNetwork 库浏览服务 (bonjour) 时 txtRecord 为 null

发布于 2024-12-19 03:29:03 字数 1077 浏览 1 评论 0原文

我目前正在使用 MYNetwork 库 Bonjour 类,并且在发现 txt 记录时遇到问题。当一个新的服务出现时,它的txt记录每次都是空的。

在我的服务器端,我以这种方式设置 txt 记录:

self.server = [[MYBonjourRegistration alloc] initWithServiceType: @"_blipecho._tcp." port:9121];
[server setString:@"Cyprian" forTXTKey:@"Name"];
[server start];

然后在浏览器上我发现并记录数据:

- (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]];

                }
            }
    }

我得到 txtRecord 的 null 值。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我爱人 2024-12-26 03:29:03

好的,得到答案了。

问题是新发现的服务尚未解决,因此没有数据。

必须先解决服务问题。

-(void)resolveService:(MYBonjourService*)service{

    service.addressLookup.continuous = YES;
    [service.addressLookup addObserver: self
                            forKeyPath: @"addresses"
                               options: NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew
                               context: NULL];
    [service queryForRecord: kDNSServiceType_NULL];
}

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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文