Getting Started with iOS network programming: Parsing Bonjour Services in iOS

Source: Internet
Author: User

Server-side Bonjour service after the successful release, the client can resolve the service through Nsnetservice, after the successful resolution, you can get the data details of the communication, such as: IP address, port and other information.

First you need to instantiate the Nsnetservice object code as follows:

-(ID) init { 
     
_service = [[Nsnetservice alloc] initwithdomain:@ "Local." 
     
type:@ "_tonyipp._tcp." name:@ "Tony"]; 
     
[_service setdelegate:self]; 
     
Set the resolution address timeout 
     
[_service resolvewithtimeout:1.0]; 
     
_services = [[Nsmutablearray alloc] init]; 
     
return self; 
     
}

Instantiating a Nsnetservice object is constructed by –initwithdomain:type:name: You do not need to specify its port. The parsing service needs to invoke the [_service resolvewithtimeout:1.0] statement, begin parsing the service, parse in the specified time, and the parameter is seconds.

#pragma mark-nsnetservicedelegate Methods 
     
-(void) Netservicewillresolve: (Nsnetservice *) Netservice { 
     
NSLog ( @ "Netservicewillresolve"); 
     
} 
     
      
     
-(void) Netservicedidresolveaddress: (Nsnetservice *) Netservice { 
     
NSLog (@ "netservicedidresolveaddress"); 
     
[_services Addobject:netservice]; 
     
} 
     
      
     
-(void) Netservice: (Nsnetservice *) Netservice didnotresolve: (nsdictionary *) errordict { 
     
NSLog (@ "Didnotresolve:% @ ", errordict); 
     
}

Netservicewillresolve: Method callback at the start of parsing, callback netservicedidresolveaddress when parsing succeeds: method, callback Netservice:didnotresolve when parsing fails: method.

This article is from the "Dongsheng" blog, please be sure to keep this source http://2009315319.blog.51cto.com/701759/1179965

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.