2013-04-24 73 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)];