Re: Understanding NSNetService and peer-to-peer streaming
Right. You need to keep track of that yourself, like with a Peer class that can hold onto those streams and act as their delegate.
NSNetService doesn't really have anything to do with those streams. All Bonjour does is service discovery: it can advertise a service you're running on some port, and it can find other services of a given type. When it resolves a service it gets the IP address and port number. But that's all Bonjour does. When you ask an NSNetService to open a connection, it just resolves the service and then calls an NSStream factory method to open a TCP socket to that IP address / port. Then it returns you the resulting streams. Its job is done. This is just a convenience method that was added later on to simplify connecting to services. Once you've opened the streams, you can remember the name of the service that you got them from. Or you can have a protocol that sends the peer name or UUID or whatever over the socket when it opens; it's up to you. —Jens PS: What you're implementing sounds exactly like what the Multipeer Connectivity framework does. Are you aware of it? You could probably save yourself a ton of work by using it.
|
|