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