2013-04-24 74 views

回答

0

你考虑过NSDistributedNotificationCenter吗?

我会建议创建一个DistributedNotificationCenter(服务器),侦听从NotificationCenter发送的通知。它应该简单地将任何收到的消息(或任何注册的兴趣)转发到对等DistributedNotificationCenters(在其他进程中运行)。

问题是这些DistributedNotificationCenters如何“找到”对方。嗯,有多种选择:

  1. 一个众所周知的DistributedNotificationCenterLocator服务(服务器)挂接起来,甚至有可能是所有消息的中央中继点(但具有可扩展性的问题)。
  2. 由于(1),但您使用服务器:DistributedNotificationCenterLocator的端口初始化您的应用程序。
  3. DistributedNotificationCenter如果它是特定于应用程序的 - 也就是说我在“server:port”上,它可以在数据库中注册。即众所周知的查找。
  4. 我不知道这个,但看到this SO answer与使用Bonjour进行服务器发现有关。听起来不错?

我还没有提供的任何代码在这里,但让我知道如果你需要任何指针...

+0

我有就可以了的样子。但我想发送消息到另一个进程并等待响应。它不能回复通知 – Qusic 2013-04-24 16:00:16

0

我找到了一个很好的指导作用。 http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DistrObjects/DistrObjects.html#//apple_ref/doc/uid/10000102-SW1

在这里,我分享我的片断:

服务器:

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

客户:

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