• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSConnection not working between processes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSConnection not working between processes


  • Subject: Re: NSConnection not working between processes
  • From: AurĂ©lien HugelĂ© <email@hidden>
  • Date: Thu, 23 Jun 2005 09:15:54 +0200

Hi !

i think i've found your problem :

On 23 juin 05, at 00:27, James Bucanek wrote:

Hello again,

I posted this problem last week and didn't get any takers. I spend the better part of another day trying to get it to work, and have lost a lot of hair in the process.

.... // cleared out for lisibility

-- DOHelper.h/.m ----------------------------

#import <Cocoa/Cocoa.h>

@interface DOHelper : NSObject
{
     NSConnection*    clientConnection;
     NSLock*          running;
}

- (id)init;
- (void)run;
- (void)doSomething:(NSString*)message;
- (void)stop;

@end

@implementation DOHelper

- (id)init
{
     if ( self = [super init] )
         {
         running = [[NSLock alloc] init];
         [running lock];
         }
     return (self);
}

- (void)run
{
     NSLog(@"DOHelper started");

     // Create a connection using two arbitrary ports
     clientConnection = [NSConnection connectionWithReceivePort:
[NSPort port] sendPort:[NSPort port]];


i suspected the probleme to be there... i tried
clientConnection = [[NSConnection defaultConnection] retain]; and your program worked !
i've never succeeded to completely understand NSPort, so i can not explain you why your solution does not work... reading the doc mames me think everything is ok... but using higher level method seems "better"...


By the way, i think you forgot to retain the connection since [NSConnection connectionWithReceivePort: [NSPort port] sendPort: [NSPort port]]; returns an autoreleased object...


// Register the connection if ([clientConnection registerName:kDOPortName]==NO) [[NSException exceptionWithName:@"Comm" reason:@"cannot register NSConnection" userInfo:nil] raise];

     // Vend ourselves to the client
     [clientConnection setRootObject:self];

     // Start a run loop to dispatch messages to this object
     [clientConnection runInNewThread];

     NSLog(@"DOHelper created connection, running...");

     [running lock];         // we'll aquire this lock when the
client tells us to stop
     [running unlock];       // release it in case anyone else is
using it for the same purpose

     NSLog(@"DOHelper terminating");
}

- (void)doSomething:(NSString*)message
{
     NSLog(@"The helper received this message: %@",message);
}

- (void)stop
{
     [running unlock];
}

@end


Hope this helps !

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSConnection not working between processes
      • From: James Bucanek <email@hidden>
References: 
 >NSConnection not working between processes (From: James Bucanek <email@hidden>)

  • Prev by Date: Re: String conversion help.
  • Next by Date: Re: NEWBIE: Core Data Orientation questions
  • Previous by thread: NSConnection not working between processes
  • Next by thread: Re: NSConnection not working between processes
  • Index(es):
    • Date
    • Thread