• 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
Distributed Objects and notficiation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Distributed Objects and notficiation


  • Subject: Distributed Objects and notficiation
  • From: email@hidden
  • Date: Tue, 27 Sep 2005 15:33:19 +0000

Hi all,
  I am attempting to get notfications via distributed objects across multiple machines.  The good news is if I have both applications running on the same machine it works.  Although now that I think about it, that may work all the time reguardless if my distrubuted objects are connected or not...anyways here is what I have done:
Server:
  Vends an object:
  <snip>
  //Configure communications
  bool createdSocket = NO;
  int socketPort = 15000;

  while (createdSocket == NO)
  {
    //Create the socket
    iSocketPort = [[NSSocketPort alloc] initWithTCPPort:socketPort];
    [iSocketPort retain];

    //Attach the connection
    inputConnection = [[NSConnection alloc] initWithReceivePort:iSocketPort sendPort:nil];

    if (inputConnection == nil)
    {
     //bumb the socket number
     socketPort = socketPort + 1;
     [iSocketPort release];
     [inputConnection release];
    } else
    {
     createdSocket = YES;
    }
  }

  NSTimeInterval replyTimeOut = 20;
  [inputConnection setRequestTimeout:replyTimeOut];
  [inputConnection setReplyTimeout:replyTimeOut];

  //Set the root object to vend
  [inputConnection setRootObject:c_PTServerObject];  //root object described below
  [inputConnection enableMultipleThreads];
  </snip>

  ---------------------------
  All c_PTServerObject is, is a class that has two functions:

  @implementation PTServerObject
  -(void)postForStartNotification
  {
   NSLog(@"Post!");

   [[NSDistributedNotificationCenter defaultCenter]
    postNotificationName:@"startTest" object:@"startTest"];

   return;
  }

  - (NSString *)getServerType
  {
   return [NSString stringWithString:@"Search Performance -- version 1.0"];
  }
  @end
  ---------------------------
Client:
  Connects to the object, and registers for notifications

 <snip>
  socketPort = [[NSSocketPort alloc] initRemoteWithTCPPort:[cleanedSocketString intValue] host:cleanedIPAddressString];
  outputConnection = [[NSConnection alloc] initWithReceivePort:nil sendPort:socketPort];

  NSTimeInterval replyTimeOut = 20;
  [outputConnection setRequestTimeout:replyTimeOut];
  [outputConnection setReplyTimeout:replyTimeOut];

  if (outputConnection == nil)
  {
    [outputConnection invalidate];
    [socketPort invalidate];
    return;
  }

  @try
  {
    m_remoteObject = [outputConnection rootProxy];
  } @catch (NSException* exp)
    {
      if ([[exp name] isEqual:NSPortTimeoutException])
      {
   [outputConnection invalidate];
   [socketPort invalidate];
   return;
      }
    }


   if ([[m_remoteObject getServerType] compare:@"Search Performance -- version 1.0"] == NSOrderedSame)
   {
     //We are connected to a good version
     NSLog(@"Connected");
   } else
     {
        [outputConnection invalidate];
    [socketPort invalidate];

   NSLog(@"Invalid Connection");
   return;
     }

   [self registerForStartNotification];  // implemented below
   </snip>

-(void)registerForStartNotification
  {
    //Register for a notification
    [[NSDistributedNotificationCenter defaultCenter]
  addObserver:self
  selector:@selector(startMessageSent:)
  name:@"startTest"
  object:@"startTest"
  suspensionBehavior:NSNotificationSuspensionBehaviorDeliverImmediately];

    return;
}
- (void)startMessageSent:(NSNotification *)notification
{
  NSString *objectValueString = [[NSString alloc] initWithString:[notification object]];
  if([objectValueString compare:@"startTest"] == NSOrderedSame)
  {
    NSLog(@"Notification");
  }
}
-----------------------------------
Finally the server calls [c_PTServerObject postForStartNotification] which posts the notfication.  When I test it, the client never gets the notification.  I hope I am missing something obvious.  Any ideas?
Thanks in advance,
Kris
 _______________________________________________
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

  • Prev by Date: Re: Fullscreen enter/exit notification [After Panther]
  • Next by Date: Re: [Q] Garbage strings appened to a string
  • Previous by thread: Re: Asynchronous binding to a remote image
  • Next by thread: Softening NSAttributedString
  • Index(es):
    • Date
    • Thread