使用分布式对象的进程之间的通

时间:2013-02-08 01:10:08

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

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

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

有没有人能告诉我我做错了什么?

1 个答案:

答案 0 :(得分:0)

[[NSRunLoop currentRunLoop] run];  

在 - (void)initServer方法中启动当前的runloop。

-(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];  
}