【问题标题】:Communication between process using Distributed Object使用分布式对象的进程之间的通信
【发布时间】:2013-02-08 01:10:08
【问题描述】:

我无法提供代理对象,它只是在尝试获取连接时卡在客户端

NSConnection *conn = [NSConnection connectionWithRegisteredName:@"server"  host:nil];

这是我如何注册连接和出售对象

//server
-(void)initServer {

NSConnection * connection = [[NSConnection alloc]init];

MZRemoteObject * obj = [[MZRemoteObject alloc]init];
obj.message = @"hello world";
[connection setRootObject:obj];
if([connection registerName:@"server"]== NO){
    NSLog(@"error Register Server");
}
NSLog(@"Registered Server");
}

客户端(获取出售对象)

- (void)recieveMessage {

NSDistantObject *proxy;
NSConnection *conn = [NSConnection connectionWithRegisteredName:@"server"  host:nil];

if (!conn) {
    NSLog(@"conn recieve message error");
}

proxy = [conn rootProxy];
MZRemoteObject * obj =(MZRemoteObject*)proxy;

if (!proxy) {
    NSLog(@"proxy,recieve message error");
}
NSLog(@"----%@",obj.message);
}

谁能告诉我我做错了什么?

【问题讨论】:

  • 你是从线程调用 initServer 吗?
  • 我从主线程调用这两种方法,但从不同的应用程序客户端应用程序和服务器应用程序
  • 你是沙盒的吗?服务器是一个实际的应用程序,而不是一个命令行工具吗?是否有任何内容写入控制台日志?您是否考虑过使用+serviceConnectionWithName:rootObject:+rootProxyForConnectionWithRegisteredName:host: 便利构造函数?

标签: objective-c xcode cocoa ipc distributed-objects


【解决方案1】:
[[NSRunLoop currentRunLoop] run];  

在 -(void)initServer 方法中启动当前运行循环。

-(void)initServer {

NSConnection * connection = [[NSConnection alloc]init];

MZRemoteObject * obj = [[MZRemoteObject alloc]init];
obj.message = @"hello world";
[connection setRootObject:obj];
if([connection registerName:@"server"]== NO){
    NSLog(@"error Register Server");
}
NSLog(@"Registered Server");
[[NSRunLoop currentRunLoop] run];  
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-29
    • 2011-01-02
    • 1970-01-01
    • 2014-09-18
    • 2019-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多