ios - What's The Difference Between NSNetService and GCDAsynSocket? -


on ios, i'm using bonjour find other devices can stream data between two. planning use nsnetservice bonjour, , cocoaasyncsocket streaming.

in this example, create gcdasyncsocket , nsnetservice on same port:

socket = [[gcdasyncsocket alloc] initwithdelegate:self delegatequeue:dispatch_get_main_queue()]; [socket acceptonport:0 error:null];  netservice = [[nsnetservice alloc] initwithdomain:@"local." type:@"_yourservicename._tcp." name:@"" port:socket.localport]; 

could explain difference between nsnetservice , gcdasyncsocket?

to me seems i'm creating 2 sockets on same port. since can create input & output streams nsnetservice.

[service getinputstream:&input outputstream:&output]; 

gcdasyncsocket used create listening server socket:

socket = [[gcdasyncsocket alloc] initwithdelegate:self delegatequeue:dispatch_get_main_queue()]; [socket acceptonport:0 error:null]; 

the port number set 0 means os picks available port.

socket.localport 

is port number chosen os socket listening on.

nsnetservice used publish service via bonjour:

netservice = [[nsnetservice alloc] initwithdomain:@"local." type:@"_yourservicename._tcp." name:@"" port:socket.localport]; [netservice setdelegate:self]; [netservice publish]; 

this not create socket, uses created port number host name , service name, , publishes information in local network (using bonjour/mdns protocol).


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -