简体   繁体   中英

Resolving NSNetService on server side

I have the problem in resolving NSNetService . i have successfully resolved NSNetService when NSNetServiceBrowser find that service.

-(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.

-(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 .

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.

# 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];
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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