1

プロキシ オブジェクトを販売することができません。接続を取得しようとすると、クライアント側でスタックするだけです

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

誰が私が間違っているのか教えてもらえますか?

4

1 に答える 1

0
[[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];  
}
于 2013-02-08T13:47:53.680 に答える