我不能设法出售代理对象,它只是停留在客户端时,试图获得连接
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);
}谁能告诉我我做错了什么?
发布于 2013-02-08 21:47:54
[[NSRunLoop currentRunLoop] run]; 在-(空)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];
}https://stackoverflow.com/questions/14764136
复制相似问题