Parsing Bonjour Service (RPM) in iOS

Source: Internet
Author: User

After the server-side Bonjour service is published successfully, the client can resolve the service through Nsnetservice, and after the successful resolution, the data details such as IP address, port and so on can be obtained.

The first step is to instantiate the Nsnetservice object code as follows:

    1. -(ID) init {
    2. _service = [[Nsnetservice alloc] initwithdomain:@ "Local."
    3. type:@ "_tonyipp._tcp" name:@ "Tony";
    4. [_service setdelegate:self];
    5. Set Resolve address timeout
    6. [_service Resolvewithtimeout:1.0];
    7. _services = [[Nsmutablearray alloc] init];
    8. return self;
    9. }

The constructor for instantiating a Nsnetservice object is –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 it in the specified time, and the parameter is in seconds.

  1. #pragma mark-nsnetservicedelegate Methods
  2. -(void) Netservicewillresolve: (Nsnetservice *) Netservice {
  3. NSLog (@ "Netservicewillresolve");
  4. }
  5. -(void) netservicedidresolveaddress: (Nsnetservice *) Netservice {
  6. NSLog (@ "netservicedidresolveaddress");
  7. [_services Addobject:netservice];
  8. }
  9. -(void) Netservice: (Nsnetservice *) Netservice didnotresolve: (nsdictionary *) errordict {
  10. NSLog (@ "Didnotresolve:%@", errordict);
  11. }

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

This article is from the "Dongsheng-ios Technical Consultant" blog, make sure to keep this source http://2009315319.blog.51cto.com/701759/1179965

Parsing Bonjour Service (RPM) in iOS

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.