我无法设法销售代理对象,它只是在尝试获取连接时卡在客户端
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);
}
有没有人能告诉我我做错了什么?
答案 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];
}