I'm hoping somebody can clear up my confusion behind the purposes of NOTIFY and M-SEARCH messages used by upnp/ssdp protocol.
My understanding is that a NOTIFY message is sent when a device wants to advertise itself to other UPNP capable devices and an M-SEARCH message is sent when a device wants to find out about other UPNP capable devices.
So then, if my device received an M-SEARCH message from some other device via broadcast address (for SSDP,239.255.255.250) , I'd respond to it with proper format:
HTTP/1.1 200 OK
CACHE-CONTROL: max-age = seconds until advertisement expires
DATE: when response was generated
EXT:
LOCATION: URL for UPnP description for root device
SERVER: OS/version UPnP/1.0 product/version
ST: search target
USN: advertisement UUID
Here is my question. Why does NOTIFY message exist in the first place? Since you send the device information back to the requested device upon seeing M-SEARCH, it seems to me that there's no point of advertising the device information in advance with NOTIFY unless if it was asked for, because other devices listening to the advertisement may or may not be available at the time NOTIFY was sent.
In other words, I'd like to know the exact purpose of NOTIFY compared to M-SEARCH, preferably with actual examples of its usage.
Or am I just misunderstanding this protocol entirely?