1

我无法出售代理对象,它只是在尝试连接时卡在客户端

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);
}

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

4

1 回答 1

0
[[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];  
}
于 2013-02-08T13:47:53.680 回答