0

I want something like this: http://iphonedevwiki.net/index.php/CPDistributedMessagingCenter

to send and receive some NSString between processes synchronously

but CPDistributedMessagingCenter is only available on iOS.

Can someone give me suggestions how to do this? Thanks! ;)

2 Answers2

0

Have you considered NSDistributedNotificationCenter?

I would suggest creating a DistributedNotificationCenter (server) that listens in on notifications sent from the NotificationCenter. It should simply relay any received messages (or any of registered interest) on to peer DistributedNotificationCenters (running in other processes).

The question there is how do these DistributedNotificationCenters "find" each other. Well, there are a number of options:

  1. A well known DistributedNotificationCenterLocator service (server) that hooks them up and may even be the central relay point for all messaging (but that has scalability questions).
  2. As (1) but you initialise your app with the server:port of the DistributedNotificationCenterLocator.
  3. DistributedNotificationCenters could register in a database if it's specific to an application - i.e. I am on "server:port". i.e. A well known lookup.
  4. I've no knowledge of this but see this SO answer relating to the use of Bonjour for server discovery. Sounds interesting?

I've not supplied any code here but let me know if you need any pointers...

Community
  • 1
  • 1
wmorrison365
  • 5,995
  • 2
  • 27
  • 40
  • I have had a look on it. But I want to send a message to another process and wait for a response. It cant reply to notification –  Apr 24 '13 at 16:00
0

I found a very good guide. http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DistrObjects/DistrObjects.html#//apple_ref/doc/uid/10000102-SW1

And here I share my snippet:

Server:

[NSConnection serviceConnectionWithName:@"your.connection.name" rootObject:self];

Client:

[[NSConnection rootProxyForConnectionWithRegisteredName:@"your.connection.name" host:nil]performSelector:@selector(a_selector_that_server_object_respond_and_return_value)];