问题
I am new to OS X and have to create an application having 2 parts - launch daemon and launch agent. The daemon is going to do stuff such as command execution, logging, etc and has to somehow communicate these results to launch agent (which would transfer them to a login item displaying a GUI, although that is a future step).
My question: How do I achieve this communication?. From what I have been able to gather so far after reading Apple docs is that my best bet is using CFSockets. Is there any alternate(simpler) way ? Does anybody have any sample tutorial/example/code that shows how to use CFSockets (I could not find any) ?.
PS: My question might be a duplicate of this one, but that question is not yet answered and so I thought of posting this.
回答1:
I was able to set up communication between my daemon and agent using CFSockets and it wasn't as bad as I had thought before. I followed the step-by-step instructions at : https://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/NetworkingTopics/Articles/UsingSocketsandSocketStreams.html (Writing a TCP-Based Server).
You could probably also try using plain BSD sockets. There is a simple example at : http://www.minek.com/files/unix_examples/poll.html (although I have not tried this out).
Good luck.
来源:https://stackoverflow.com/questions/11868069/os-x-communication-between-launch-daemon-and-launch-agent