简体   繁体   English

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

[英]Communication between process using Distributed Object

I can't manage to vend proxy object, it just stuck on client side when try to get connection 我无法出售代理对象,当尝试建立连接时,它只是卡在客户端

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

Here is how I register connection and vend object 这是我注册连接和出售对象的方法

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

Client side(getting vended object) 客户端(获取被售对象)

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

Could any one tell me what I am doing wrong ? 有人能告诉我我做错了吗?

[[NSRunLoop currentRunLoop] run];  

Start the current runloop in -(void)initServer method. 在-(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];  
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM