1

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 ?

Parag Bafna
  • 22,812
  • 8
  • 71
  • 144
Andrew
  • 885
  • 1
  • 10
  • 15
  • Are you calling initServer from thread ? – Parag Bafna Feb 08 '13 at 13:44
  • I call both methods from main thread, but from diferent apps Client app and Server app – Andrew Feb 08 '13 at 14:06
  • Are you sandboxed? Is the server an actual application, rather than, say, a command-line tool? Is anything written to the console log? Have you considered using the `+serviceConnectionWithName:rootObject:` and `+rootProxyForConnectionWithRegisteredName:host:` convenience constructors? – Ken Thomases Feb 10 '13 at 18:32

1 Answers1

0
[[NSRunLoop currentRunLoop] run];  

Start the current runloop in -(void)initServer method.

-(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];  
}
Parag Bafna
  • 22,812
  • 8
  • 71
  • 144