Need help implementing interprocess communication in cocoa

I developed a cocoa app and now I need to run multiple instances (locally). But all running application instances must share some resources.

So I decided to create a third "server" type application that could use the token and share the required resources.

Then I look for a way to do this and find the Distributed Objects solution.

Then I started implementing it using a few examples found on the internet, but always has warnings or errors regarding deprecation or ATC ...

Can someone give me a fresh example on how to implement this?

EDIT:

What I need to do is:

  • Identifying each instance of the application on the server
  • The application sends a Start request to the server and waits for a token before starting the required process.
  • The server uses a FIFO stack to store the Start request
  • The server gives the token to the application instance
  • The application sends "end of process" to the server, which gives the token to the next instance of the application, etc.
  • The server also has to deal with shutting down the application

Thank you for your help,

+3


source to share


1 answer


You probably want to use XPC services, not distributed objects . XPC is newer and Sandbox friendly (critical if you want to distribute it via the App Store). The Daemons and Services Development Guide gives you a conceptual overview of XPC and then some.

You want to decide how best to design your application, however, as you know best about your requirements. See Designing Daemons and Services for an overview of possible routes and best practices for overall design. If your application runs entirely in user space (not "for all users on the system"), you can go with a "login" as your server application if you want to provide an interface for launching and managing tasks.

The tasks themselves will be instances of the XPC service . If my assumptions are correct, you probably want to use the NSXPCConnection API (high level XPC API) for your remote procedure calls between a login item application and its XPC service . You will create and hold an NSXPCInterface instance for your application using the protocol you developed. For each instance of the task you run, you will use the interface to set the NSXPCConnection (each of which you will also hold down until this is done).



The service listener instance will interact with the service delegation object (your project) to decide whether to accept the connection and how to respond to your interface protocol. Once you've established a connection (there are a few steps outlined in the links above), you can start sending protocol-defined messages through your connection instance -remoteObjectProxy

(ex:) [[myConnection remoteObjectProxy] makeARandomCatMemeWithImageAtURL:someURL];

. The service will return your application with some response (by calling the application methods -exportedObject provided through its connection).

The details and approach vary somewhat (to "login item" or "start daemon / agent" etc.) if the main application is multi-user or you are going to communicate with a service running on a different host, but I am answering based on what i think you are trying to achieve.

Hope this helps.

+2


source







All Articles