XPC Launchd Service and multiple clients

Hi,


I have a need for a launchd daemon running in the root process, a launchd agent running in a user context, and a CLI that runs in the user context. I've successfully built all three in a POC. I'm using NSXPC to provide bidirectional communication. The daemon is the XPC "server" and the other two are the XPC "clients". I have a server XPC protocol and a client XPC protocol defined and implemented in all three. The daemon's XPC registers the server protocol as its exported interface and the client protocol as the remote interface. The agent and CLI's XPC registers the server protocol as the remote interface and the client protocal as the exported interface.


The breakdown that I'm seeing is that only one of the clients will receive client XPC communications. If I launch one, it will receive it until the next one is launched. Then the next one seems to hijack the first one's client messages. So in effect, it seems there can only be one client process. Is this the case with XPC?

Replies

Is this the case with XPC?

No. I’m not entirely sure what you’re doing wrong here, but there’s a couple of approaches that folks usually use take:

  • If the protocol is strictly request/response, there’s really no extra work required for the server to handle multiple clients.

  • If the server needs to send unsolicited messages to the client, the server usually creates a separate connection for each client. Check out

    +anonymousListener
    , the
    endpoint
    property, and
    -initWithListenerEndpoint:
    .

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks. Now I just have to figure out how to implement it. I'm a bit new to this. 🙂

@jasosimm have you last succeeded in this? my situation is very similar, and bidirectional simply doesn't work for me. I wonder what I'm doing wrong. If you managed to make it work, maybe paste here the few relevant lines of code that demonstrate the flow?
I responded on the other thread where you asked this.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"