Re: Trying to get hang of PDO
Re: Trying to get hang of PDO
- Subject: Re: Trying to get hang of PDO
- From: "Waldo Lee Sharvey" <email@hidden>
- Date: Wed, 18 Jun 2008 14:54:30 -0400
Whoops, I had a typo on ClientController's nameserver's portname (it was
supposed to be "CommServerPort" and not "ChatterPort")
Fixed this, but now I'm getting crashes when the debugger hits [[connect
rootProxy] retain].
On Wed, Jun 18, 2008 at 2:40 PM, Waldo Lee Sharvey <
email@hidden> wrote:
>
> For the last several days I've been trying to use Distributed Objects in my
> application to no avail. I've scanned and scoured for multiple pieces of
> documentation over just about everywhere, I've tried one variation of code
> after another, initially trying to use NSSocketPort with domain sockets and
> then dropping down to NSMessagePorts w/ name server (to rule out any socket
> programming issues) and still nothing works.
>
> The below is a mini-sized, minimalistic version of what I've been trying to
> write. It's largely based off the example I found in the Advanced Mac
> Programming book. My (simplified for the time being) goal is to create a
> foundation-tool based daemon that vends a communication object that will let
> a client Cocoa application connect and register as a client via distributed
> objects.
>
> The server seems to run okay, but the client tries to get the vended
> NSMessagePort sendPort, sendPort shows up as nil in the debugger. What am I
> doing wrong/misunderstanding?
>
> ######### Protocol ##################################
>
> #import <Foundation/Foundation.h>
>
> @protocol ClientMessages
>
> - (oneway void)printHelloWorld:(NSString *)barcode;
>
> @end
>
> @protocol ServerMessages
>
> - (BOOL)subscribeClient:(in byref id<ClientMessages>)newclient;
>
> @end
>
> ######### Daemon Code ################################
>
> #import <Foundation/Foundation.h>
> #import "CommManager.h"
>
>
> int main (int argc, const char * argv[])
> {
> NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
> NSRunLoop *runloop = [NSRunLoop currentRunLoop];
> CommManager *commManager = [[CommManager alloc] init];
> NSMessagePort *receivePort = [[NSMessagePort alloc] init];
> NSMessagePortNameServer *mpns = [NSMessagePortNameServer sharedInstance];
> [mpns registerPort:receivePort name:@"CommServerPort"];
> NSConnection *connection = [NSConnection
> connectionWithReceivePort:receivePort sendPort:nil];
>
> [connection setRootObject: commManager];
> [runloop run];
> [pool drain];
> return 0;
> }
>
> ####### CommManager.h #####################
>
> #import <Foundation/Foundation.h>
> #import "CommProtocol.h"
>
> @interface CommManager : NSObject <ServerMessages>
> {
> NSMutableArray *clients;
> }
>
> @end
>
> ###### CommManager.m ######################
>
> #import "CommManager.h"
> #import "CommProtocol.h"
>
> @implementation CommManager
>
> - (BOOL)subscribeClient:(in byref id<ClientMessages>)newclient
> {
> [clients addObject: newclient];
> return YES;
> }
>
> - (void)dealloc
> {
> [clients release];
> [super dealloc];
> }
>
> @end
>
>
> ########### ClientController.h #################################
>
> #import <Cocoa/Cocoa.h>
> #import "CommProtocol.h"
>
> @interface ClientController : NSObject <ClientMessages>
> {
> id proxy;
> }
>
> @end
>
> ########### ClientController.m #################################
>
>
> #import "ClientController.h"
>
>
> @implementation ClientController
>
> - (void)awakeFromNib
> {
> NSMessagePortNameServer *nameServer = [NSMessagePortNameServer
> sharedInstance];
> // sendPort shows up as nil in the debugger
> NSMessagePort *sendPort = [nameServer portForName:@"ChatterPort"];
> NSConnection *connection = [NSConnection connectionWithReceivePort:nil
> sendPort: sendPort];
> proxy = [[connection rootProxy] retain];
> [proxy setProtocolForProxy:@protocol(ServerMessages)];
> BOOL successful = [proxy subscribeClient: self];
> if(successful)
> {
> NSLog(@"connected");
> }
> else
> {
> NSLog(@"not connected");
> }
> }
>
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden