5

I'm using DO with for IPC. I used following code. Its working fine in 10.6 and 10.7 but on 10.8 die even both application were ideal.

// HELPER

NSConnection *connection =[NSConnection new];
[[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(connectionDidDie:)
                                                  name:NSConnectionDidDieNotification
                                                   object:nil];
[connection setRootObject:syncManager];  
if ([connection registerName:SYNC_SERVER_NAME] == NO){
       NSLog(@"Error registering server");
} 
- (void)connectionDidDie:(NSNotification *)aNotification{ 
     NSConnection     *deadConnection = [aNotification object];
     id    currentClient = [self.clientsList objectAtIndex:0];
     NS_DURING
     if([currentClient respondsToSelector:@selector(connectionForProxy)]) {
          if(deadConnection == [currentClient connectionForProxy]){
                 // remove proxy with dead connection
                 [clientsList removeObjectAtIndex:0];
                 NSLog(@"Removed client from client list.");
           }
     }
     NS_HANDLER
     [self.clientsList removeObjectAtIndex:0];
     NS_ENDHANDLER

}

// UI App

// ------
self.server = [NSConnection rootProxyForConnectionWithRegisteredName:SYNC_SERVER_NAME host:nil];
if(nil != self.server){
[[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(connectionDidDie:)
                                                     name:NSConnectionDidDieNotification
                                                   object:nil];
[self.server addMessageClient:self];
[self.server setProtocolForProxy:@protocol(MDMessageProtocol)];
//------

- (void)connectionDidDie:(NSNotification *)aNotification{
    NSLog(@"Error: Connection to server is broken");
}
mandeep-dhiman
  • 2,505
  • 2
  • 21
  • 31
  • 3
    This probably isn't helpful to you, but Distributed Objects is pretty much dead at this point. Regardless of the mechanism (DO, XPC, web services, UNIX sockets, etc) you're always going to have to be prepared to handle lost connections in any distributed application. Your efforts would probably be better spent writing code to recover from (inevitable) lost connections than trying to understand what changed between 10.7 and 10.8 that is causing more of them. – ipmcc Feb 03 '13 at 19:53

0 Answers0