简体   繁体   English

OS X上CPDistributedMessagingCenter的替代品吗?

[英]any alternative to CPDistributedMessagingCenter on OS X?

I want something like this: http://iphonedevwiki.net/index.php/CPDistributedMessagingCenter 我想要这样的东西: http : //iphonedevwiki.net/index.php/CPDistributedMessagingCenter

to send and receive some NSString between processes synchronously 在进程之间同步发送和接收一些NSString

but CPDistributedMessagingCenter is only available on iOS. 但是CPDistributedMessagingCenter仅在iOS上可用。

Can someone give me suggestions how to do this? 有人可以给我一些建议吗? Thanks! 谢谢! ;) ;)

Have you considered NSDistributedNotificationCenter ? 您是否考虑过NSDistributedNotificationCenter

I would suggest creating a DistributedNotificationCenter (server) that listens in on notifications sent from the NotificationCenter . 我建议创建一个DistributedNotificationCenter (服务器),以侦听从NotificationCenter发送的NotificationCenter It should simply relay any received messages (or any of registered interest) on to peer DistributedNotificationCenters (running in other processes). 它应该仅将任何接收到的消息(或任何已注册的感兴趣消息)中继到对等的DistributedNotificationCenters (在其他进程中运行)。

The question there is how do these DistributedNotificationCenters "find" each other. 这里的问题是这些DistributedNotificationCenters如何彼此“查找”。 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). 众所周知的DistributedNotificationCenterLocator服务(服务器)将它们连接起来,甚至可能是所有消息传递的中央中继点(但是存在可伸缩性问题)。
  2. As (1) but you initialise your app with the server:port of the DistributedNotificationCenterLocator . 与(1)一样,但是您使用DistributedNotificationCenterLocator的server:port初始化您的应用程序。
  3. DistributedNotificationCenter s could register in a database if it's specific to an application - ie I am on "server:port". DistributedNotificationCenter特定于应用程序,则可以在数据库中注册-即我在“ server:port”上。 ie 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. 我对此一无所知,但看到了与将Bonjour用于服务器发现有关的SO答案 Sounds interesting? 听起来不错?

I've not supplied any code here but let me know if you need any pointers... 我在这里没有提供任何代码,但是如果您需要任何指针,请告诉我...

I found a very good guide. 我找到了一个很好的指南。 http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DistrObjects/DistrObjects.html#//apple_ref/doc/uid/10000102-SW1 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)];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM