[英]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: 好吧,有很多选择:
DistributedNotificationCenterLocator
service (server) that hooks them up and may even be the central relay point for all messaging (but that has scalability questions). 众所周知的DistributedNotificationCenterLocator
服务(服务器)将它们连接起来,甚至可能是所有消息传递的中央中继点(但是存在可伸缩性问题)。 DistributedNotificationCenterLocator
. 与(1)一样,但是您使用DistributedNotificationCenterLocator
的server:port初始化您的应用程序。 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. 即众所周知的查找。 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.