DOs and DOn'ts

  • I am aware of the recent (and extensive) discussion of DO.  However, I think
    I'm missing something.  I cannot seem to get a vended object no matter what
    I do.  I have a daemon and a small program that needs to be launched.  It
    launches the program, everything compiles without a hitch; but the proxy is
    always null.  In the server program, the relevant code is this:
    NSConnection * openServer(id vendedObject)
    {
      NSConnection * theConnection=[NSConnection defaultConnection];
        [theConnection setRootObject:vendedObject];
              if([theConnection registerName:@"myServer"]==NO)
                {
                  NSLog(@"Error registering connection!  Terminating
    abnormally!\n");
                  exit(255);
                }
      [theConnection runInNewThread];
          return theConnection;
    }

    in the rest of the code, I use [[NSRunLoop
    currentRunLoop]configureAsServer], and then, just after launching the
    client, where the call comes, I have the current run loop run for 60
    seconds.
    Then, voila.  null.  My relevant code in the client is pretty basic:

      id * theProxy = [[NSConnection
      rootProxyForConnectionWithRegisteredName:@"myServer"
                                          host:nil] retain];//I've used both
    nil and @"*" to no avail
      NSLog(@"the proxy is of class %@\n", [theProxy class]);
      NSLog(@"The name of the vended object is %@\n", [theProxy getName]);/*the
    vended object has a name, and responds to this method*/

    Both NSLogs report (null), and I'm completely lost as to why.  I've checked
    the web on multiple tutorials/docs/etc., read and reread the manual.  I must
    be missing something terribly obvious.

    Again, if this has already been solved and discussed, I apologize.  Three
    times.  Once for wasting your time reading the email, again for not paying
    closer attention, and finally for using everyone else's  bandwidth.

    Thanks in advance,
    --
    Isaac Sherman
    MotaSoft Software
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • Isaac,

    >>>>>> Isaac Sherman (IS) wrote at Mon, 25 Feb 2002 18:11:23 -0500:
    IS> id * theProxy = [[NSConnection
    IS> rootProxyForConnectionWithRegisteredName:@"myServer"
    IS> host:nil] retain];//I've used both
    IS> nil and @"*" to no avail
    IS> NSLog(@"the proxy is of class %@\n", [theProxy class]);
    IS> NSLog(@"The name of the vended object is %@\n", [theProxy getName]);/*the
    IS> vended object has a name, and responds to this method*/
    IS>
    IS>
    IS> Both NSLogs report (null), and I'm completely lost as to why.

    That makes two of us. This looks reasonably. Are you sure you (a) use
    host:nil, and (b) have both the server and client running on the same
    machine?

    Anyway, this one does work:

    114 /tmp> cat q.m
    // simplest server/client via DO
    #import <Foundation/Foundation.h>
    #define NAME @"Just test"
    void main() {
      NSAutoreleasePool *pool=[NSAutoreleasePool new];
      id server=[NSConnection rootProxyForConnectionWithRegisteredName:NAME host:nil];

      if (server) {
        NSLog(@"I'm a client just now. I'm about to send a message...");
            NSLog(@"with the result %@",[server description]);
            NSLog(@"That's all, bye!");
      } else {
        NSConnection *conn=[NSConnection defaultConnection];
            NSLog(@"I'm here to serve!");
            [conn setRootObject:[NSScanner new]]; // use any class you want to here
            if (![conn registerName:NAME]) NSLog(@"Oops?!?");
        else {
              [conn runInNewThread];
              NSLog(@"enter 'q' and press Enter to quit");
              while (getchar()!='q');
            }
      }
      [pool release];
    }
    115 /tmp> cc -Wall -framework Foundation q.m -o q
    q.m:4: warning: return type of `main' is not `int'
    116 /tmp> ./q
    2002-02-26 22:56:58.187 q[1956] I'm here to serve!
    2002-02-26 22:56:58.193 q[1956] enter 'q' and press Enter to quit
    ^Z
    zsh: suspended  ./q
    117 /tmp> bg %%
    [2]  - continued  ./q
    118 /tmp> ./q
    2002-02-26 22:57:10.175 q[1957] I'm a client just now. I'm about to send a
    message...
    2002-02-26 22:57:10.181 q[1957] with the result <NSConcreteScanner: 0x949c0>
    2002-02-26 22:57:10.183 q[1957] That's all, bye!
    119 /tmp>
    ---
    Ondra Cada
    OCSoftware:    <ocs...>              http://www.ocs.cz
    2K Development: <o.cada...>  http://www.2kdevelopment.cz
    private        <ondra...>            http://www.ocs.cz/oc
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • on 2/26/02 4:57 PM, you, Ondra Cada, at the address, <ocs...>,  wrote:

    > Isaac,
    >
    >>>>>>> Isaac Sherman (IS) wrote at Mon, 25 Feb 2002 18:11:23 -0500:
    > IS> id * theProxy = [[NSConnection
    > IS> rootProxyForConnectionWithRegisteredName:@"myServer"
    > IS> host:nil] retain];//I've used both
    > IS> nil and @"*" to no avail
    > IS> NSLog(@"the proxy is of class %@\n", [theProxy class]);
    > IS> NSLog(@"The name of the vended object is %@\n", [theProxy getName]);/*the
    > IS> vended object has a name, and responds to this method*/
    > IS>
    > IS>
    > IS> Both NSLogs report (null), and I'm completely lost as to why.
    >
    > That makes two of us. This looks reasonably. Are you sure you (a) use
    > host:nil, and (b) have both the server and client running on the same
    > machine?
    >
    > Anyway, this one does work:
    >
    > 114 /tmp> cat q.m
    > // simplest server/client via DO
    > #import <Foundation/Foundation.h>
    > #define NAME @"Just test"
    > void main() {
    > NSAutoreleasePool *pool=[NSAutoreleasePool new];
    > id server=[NSConnection rootProxyForConnectionWithRegisteredName:NAME
    > host:nil];
    >
    > if (server) {
    > NSLog(@"I'm a client just now. I'm about to send a message...");
    > NSLog(@"with the result %@",[server description]);
    > NSLog(@"That's all, bye!");
    > } else {
    > NSConnection *conn=[NSConnection defaultConnection];
    > NSLog(@"I'm here to serve!");
    > [conn setRootObject:[NSScanner new]]; // use any class you want to here
    > if (![conn registerName:NAME]) NSLog(@"Oops?!?");
    > else {
    > [conn runInNewThread];
    > NSLog(@"enter 'q' and press Enter to quit");
    > while (getchar()!='q');
    > }
    > }
    > [pool release];
    > }
    > 115 /tmp> cc -Wall -framework Foundation q.m -o q
    > q.m:4: warning: return type of `main' is not `int'
    > 116 /tmp> ./q
    > 2002-02-26 22:56:58.187 q[1956] I'm here to serve!
    > 2002-02-26 22:56:58.193 q[1956] enter 'q' and press Enter to quit
    > ^Z
    > zsh: suspended  ./q
    > 117 /tmp> bg %%
    > [2]  - continued  ./q
    > 118 /tmp> ./q
    > 2002-02-26 22:57:10.175 q[1957] I'm a client just now. I'm about to send a
    > message...
    > 2002-02-26 22:57:10.181 q[1957] with the result <NSConcreteScanner: 0x949c0>
    > 2002-02-26 22:57:10.183 q[1957] That's all, bye!
    > 119 /tmp>
    > ---
    > Ondra Cada
    > OCSoftware:    <ocs...>              http://www.ocs.cz
    > 2K Development: <o.cada...>  http://www.2kdevelopment.cz
    > private        <ondra...>            http://www.ocs.cz/oc
    > _______________________________________________
    > cocoa-dev mailing list | <cocoa-dev...>
    > Help/Unsubscribe/Archives:
    > http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    > Do not post admin requests to the list. They will be ignored.

    Very odd.  In Terminal (as well as Project Builder) server reports null, and
    never enters the "I'm a client..." section.  Which, at first glance to me,
    looks like a problem with my framework specifically.  Any ideas?  Should I
    re-install OS X, or maybe just the frameworks (if that's doable)?
    --
    Isaac Sherman
    MotaSoft Software
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
previous month february 2002 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28      
Go to today