gpt4 book ai didi

objective-c - 使用分布式对象的进程之间的通信

转载 作者:行者123 更新时间:2023-12-03 17:23:16 26 4
gpt4 key购买 nike

我无法设法提供代理对象,当尝试获取连接时它只是停留在客户端

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

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

最佳答案

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

关于objective-c - 使用分布式对象的进程之间的通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14764136/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com