简体   繁体   English

在服务器端解析NSNetService

[英]Resolving NSNetService on server side

I have the problem in resolving NSNetService . 我在解决NSNetService问题。 i have successfully resolved NSNetService when NSNetServiceBrowser find that service. NSNetServiceBrowser找到该服务时,我已经成功解析了NSNetService

-(void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didFindService:(NSNetService *)aNetService moreComing:(BOOL)moreComing{

    if (![self.services containsObject:aNetService]) {

        [aNetService setDelegate:self];
        [aNetService resolveWithTimeout:5.0];
    }
}

then this method is successfully called 那么这个方法被成功调用

-(void)netServiceDidResolveAddress:(NSNetService *)sender{

    NSArray *addresses = [ns addresses]; 
    NSDictionary* dict = [NSNetService dictionaryFromTXTRecordData:[sender TXTRecordData]];
    // Here both values are ok
}

but i want to resolve NSNetService to server side to get the IP address on which that service is published. 但我想将NSNetService解析到服务器端,以获取在其上发布该服务的IP地址。

-(void)netServiceDidPublish:(NSNetService *)ns{

    [ns setDelegate:self];
    [ns resolveWithTimeout:5.0];
}

but here this method is not calling. 但是这里没有调用此方法。

-(void)netServiceDidResolveAddress:(NSNetService *)sender{
   
}

however i did this 但是我这样做

-(void)netServiceDidPublish:(NSNetService *)ns
{
    NSArray *addresses = [ns addresses]; // this gives null

    // this also gives null
    NSDictionary* dict = [NSNetService dictionaryFromTXTRecordData:[sender TXTRecordData]];
}

but values are null . 但是值是null

please help me if it is possible. 如果可以的话,请帮助我。 any help will be appreciated. 任何帮助将不胜感激。 thanks in advance. 提前致谢。

Had this problem the other day as well, and took me a while to figure it out. 前几天也有这个问题,花了我一段时间才解决。 For some reason, I needed to assign aNetService to a property. 由于某些原因,我需要将aNetService分配给属性。

# Declare a NSNetService property in the .h or further up .m file
@property (strong, nonatomic) NSNetService *currentService;

# In the .m file.
-(void)netServiceBrowser:(NSNetServiceBrowser *)aNetServiceBrowser didFindService:(NSNetService *)aNetService moreComing:(BOOL)moreComing{

    if (![self.services containsObject:aNetService]) {
        self.currentService = aNetService;
        [self.currentService setDelegate:self];
        [self.currentService resolveWithTimeout:5.0];
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM