Discovering what's out there

Discovering what's out there

Many of us feel nervous when meeting a group of people for the first time. What are the dynamics of the group, what are the in-jokes, will I find common ground with someone - are just a few questions that can plague you. A lot of your hard work at suppressing your crippling social self-doubt can unravel with a shaky introduction or misplaced comment. You may even find yourself wondering:

[…]

A request message is when a control point transmits an M-SEARCH message onto the network e.g.

[…]

An update message allows changes to a service to be shared. An update message is also a multicast NOTIFY message like the alive message e.g.

[…]

A byebye message allows interested nodes to know when a service is about to be removed from the network. A byebye message should be sent for each valid (non-expired) alive message that was sent. A byebye message is a multicast NOTIFY message e.g.

[…]

This post will gradually build up to a working example however if you want to jump ahead then head on over to the completed example and take a look at SSDPSearchSessionConfiguration, SSDPSearchSession, SSDPServiceParser and SSDPService to see how things end up.

[…]

To get an SSDPService instance, it needs to be parsed:

I could have combined SSDPService and SSDPServiceParser into the one type, but I prefer to have them as two separate types to make reading SSDPService easier.

[…]

With the above changes, a new M-Search message is sent every maximumWaitResponseTime seconds.

However while making SSDPSearchSession a more reliable discovery service, sending multiple M-Search messages creates a new problem. In ideal network conditions, the same SSDP service would respond to each sent M-Search message. If these responses were just blindly passed to the delegate, the SSDPSearchService instance would in effect be spamming that delegate with the same service multiple times. Thankfully each service parsed is already stored in the servicesFoundDuringSearch array (to be used when searchSessionDidStopSearch(_:, foundServices:) is called), so to prevent becoming a spammer a check can be made to determine if an SSDPService instance representing the same service has already been passed to the delegate:

[…]