2 Replies
      Latest reply: Feb 20, 2017 3:06 PM by jasosimm RSS
      jasosimm Level 1 Level 1 (0 points)

        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?

        • Re: XPC Launchd Service and multiple clients
          eskimo Apple Staff Apple Staff (6,015 points)

          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"