CocoaDev

Edit AllPages

Example code for server and client threads communication using DistributedObjects.

The code is based on Apple article (http://developer.apple.com/documentation/Cocoa/Conceptual/Multithreading/articles/CocoaDOComm.html) and DistributedObjectsForInterThreadCommsCrash.

Notes:

Issues:

//// Server.h

/*

Creating a server thread

Client call [Server connectionToServerThreadForClient:self] to create a server thread and get back a connection to the thread. When the thread is ready, it will call the client setServer: method. After the client set the server, it can communicate with the server over DO.

Destroying a server thread

Client call [server terminate], then release the server as usual.

*/

@protocol Server

// Terminate the server thread

// Add other methods that servers must have

@end

@protocol Client

// Called from the server when its ready

// Add other methods that clients must have

@end

@interface Server : NSObject { BOOL running; }

// Create new thread and get back a connection the thread

// Private method used only by the Server class to connect to a new created thread

@end

//// Server.m

@implementation Server

@end

//// Client.h

#import Server.h // for Client protocol

@interface Client : [[NSObject { id server; NSConnection *serverConnection; } @end

//// Client.m

@implementation Client

@end

–NirSoffer