IOS network programming-Parse bonjour service in IOS

Source: Internet
Author: User

After the Bonjour service on the server is successfully published, the client can use nsnetservice to parse the service. After successful resolution, the client can obtain the details of the communication data, such as the IP address and port.

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 [_ service resolvewithtimeout: 1.0] When the resolution address times out. _ services = [[nsmutablearray alloc] init]; return self ;}

 

 

The construction method for instantiating the nsnetservice object is-initwithdomain: Type: Name:. You do not need to specify its port. The Resolution Service must call the [_ service resolvewithtimeout: 1.0] statement to start parsing the service. The parameter is in 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: The method is called back at the resolution start, and netservicedidresolveaddress: method when the resolution is successful. netservice: didnotresolve: method is called back when the resolution fails.

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.