I'm not sure if I've just missed some documentation or not, but I'm having a hard time figuring out how to set up a launchd
agent that can be triggered whenever a datagram is received within a multicast group.
What I'd like to know is what a launchd
plist should look like to provide a simple datagram listener that is bound to a multicast group.
Here's what I've been trying:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>foo.bar</string>
<key>Program</key>
<string>/foo/bar</string>
<key>Sockets</key>
<dict>
<key>Listeners</key>
<dict>
<key>SockType</key>
<string>dgram</string>
<key>SockServiceName</key>
<string>12345</string>
<key>SockFamily</key>
<string>IPv4</string>
<key>MulticastSocket</key>
<string>224.0.0.253</string>
</dict>
</dict>
<key>inetdCompatibility</key>
<dict>
<key>Wait</key>
<false/>
</dict>
</dict>
</plist>
But it just generates getaddrinfo
errors ("nodename nor servname provided, or not known"). Removing the multicast group to just setup a UDP port seems to work fine, but I don't really want to have to hard code an IP address or local DNS.
Are there any good examples of how to create a multicast listening launch agent or daemon using launchd
? Or am I missing some other step, or misunderstanding what data I should be entering for a multicast group?
echo 'My message' | nc -uw 1 localhost 6000
to send the message to a service listening to port 6000 on your local machine. Not sure ifnc
supports sending multicast messages (I don't see an option) but it lets you test when sending directly to a single machine.