discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Detecting running application


From: Richard Frith-Macdonald
Subject: Re: Detecting running application
Date: Thu, 11 May 2006 16:18:20 +0100


On 11 May 2006, at 16:05, Chris B. Vetter wrote:

On 5/11/06, Richard Frith-Macdonald <address@hidden> wrote:
[...]
1. Creates an NSMessagePort instance
2. calls [NSMessagePortNameServer-registerPort:forname:] useing the
newly created port and a unique identifier for the bundle
[...]

That is exactly what I was trying to do:

- (id) init
{
   id server = nil, port = nil;

   server = [NSMessagePortNameServer sharedInstance];
   port = [server portForName: @"Foobar"];

   if( ! port )
   {
     NSLog(@"no port, creating");
     port = [NSMessagePort port];
   }

   if( [server registerPort: port forName: @"Foobar"] )
   {
     NSLog(@"registered");
     return self;
   }
   return nil;
}

Both instances will tell me that there is no port, therefor create a
new one and register.

Probably your code is not retaining the port ... so by the time the second program runs, the port in the first program has been released.
When I took essentially the same code it worked as expected ...

int main ()
{
  id server = [NSMessagePortNameServer sharedInstance];
  id port = [server portForName: @"Foobar"];

  if (!port)
    {
      NSLog(@"no port, creating");
      port = [NSMessagePort port];
    }
  if ([server registerPort: port forName: @"Foobar"])
    {
      NSLog(@"registered");
      sleep(60);
    }
  else
    {
      NSLog(@"not registered");
    }
  exit (0);
}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]