GCDAsyncSocket is used to create a listening server socket:
socket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
[socket acceptOnPort:0 error:NULL];
The port number is set to 0 which means that the OS picks an available port.
socket.localPort
is the port number chosen by the OS that the socket is then listening on.
NSNetService is used to publish the service via Bonjour:
netService = [[NSNetService alloc] initWithDomain:@"local." type:@"_YourServiceName._tcp." name:@"" port:socket.localPort];
[netService setDelegate:self];
[netService publish];
This does not create another socket, but uses the created port number together with the host name and service name, and publishes this information in the local network (using the Bonjour/mDNS protocol).