Results 1 to 3 of 3
  1. #1


    Member Since
    Apr 24, 2010
    Location
    Ireland
    Posts
    5
    Specs:
    Dual 1GHz G4 OSX10.4.11
    Distributed Object (newbie problem)
    Hello

    I am relatively new to Cocoa but learning fast.
    I have a specific problem which I hope may be answered by the
    expertise on this forum.

    I cannot seem to get a 'client' app to make a connection to a vended
    object in a 'server' app. The relevant code in my 'server' app is:

    - (void)awakeFromNib {

    // create the comms port for receiving
    port = [[[NSSocketPort alloc] initWithTCPPort:60000] retain];
    NSLog(@"Socket Port = %@", [port address]);

    // set up, retain and register connection
    connection = [[[NSConnection alloc] initWithReceivePort: port sendPort: nil] retain];
    [connection registerName: @"medix"];

    [connection setRootObject:self];

    NSLog(@"Connection = %@", connection);

    }


    This seems to work fine. The port is open and the NSLog confirms the
    structure of the connection.

    The problem lies in my 'client' code (I think):

    - (void)awakeFromNib {

    // set up and retain connection
    connection = [[NSConnection connectionWithRegisteredName:@"medix" host:@"192.168.1.2"] retain];

    NSLog(@"Connection Setup %@\n\n\n", connection);

    remObject = [connection rootProxy];

    NSLog(@"Connection Setup %@\n\n\n", remObject);

    [remObject retain];

    }


    .. which refuses to connect and which does NOT display the remObject
    structure in NSLog, but simply (null).

    Am I doing something so obviously crazy that I can't see it ? ?

    Thanks in advance

    Chris

  2. #2


    Member Since
    Apr 24, 2010
    Location
    Ireland
    Posts
    5
    Specs:
    Dual 1GHz G4 OSX10.4.11
    Problem solved by me after much trial and error work !
    -
    In the 'server', use:

    - (void)awakeFromNib {

    port = [[NSSocketPort alloc] initWithTCPPort:60000];

    connection = [[[NSConnection alloc] initWithReceivePort:port sendPort:port] retain];

    [connection setRootObject:self];

    return;

    }


    In the 'client', use:

    - (void)awakeFromNib {

    port = [[NSSocketPort alloc] initRemoteWithTCPPort:60000 host:@"192.168.1.2"];

    connection = [[[NSConnection alloc] initWithReceivePort:nil sendPort:port] retain];

    remObject = [[connection rootProxy] retain];

    return;
    }


    This does not require registration with a port name server or any
    other code overhead, and seems to work flawlessly.

    Just in case anyone else is struggling with this.
    Woefully poor explanations in most textbooks and in the Apple
    documentation, as per usual

    Chris

  3. #3


    Member Since
    Apr 24, 2010
    Location
    Ireland
    Posts
    5
    Specs:
    Dual 1GHz G4 OSX10.4.11
    PS:

    Of course, as this is in an -awakeFromNib method I have to release the
    connection objects and the proxy if the window gets closed and reopened
    in the app otherwise it will leak like fun.

    Chris

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Distributed Objects
    By sfurlani in forum OS X - Development and Darwin
    Replies: 0
    Last Post: 11-18-2009, 03:13 PM
  2. Object-C Newbie Question
    By iMarco in forum OS X - Development and Darwin
    Replies: 1
    Last Post: 11-04-2009, 09:02 AM
  3. Object selection problem (Illustrator)
    By mcjacksonnelson in forum Images, Graphic Design, and Digital Photography
    Replies: 1
    Last Post: 03-13-2009, 03:24 AM
  4. Distributed Issue Tracking
    By stay[c]runchy in forum OS X - Development and Darwin
    Replies: 0
    Last Post: 02-14-2009, 03:43 AM
  5. Shared or Distributed Memory?
    By Debra Baker in forum OS X - Development and Darwin
    Replies: 0
    Last Post: 01-31-2008, 01:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •