Distributed Objects Demo
This XCode project was created for a DTS bug report to demonstrate a thread-related port leak in Cocoa’s Distributed Objects implementation (Tiger and earlier), but in the process it also demonstrates:
1.Single threaded DO
2.Multi-threaded DO
3.Use of NSPortNameServer (a Bonjour wrapper, basically).
The port leak seems to have been fixed in Leopard.
The code was never intended as a tutorial, but lucid DO tutorial code is pretty rare, and code that demonstrates the obscure NSPortNameServer technique is rarer still.
This project produces an application which controls both the server and the client in the same window. If you want to explore DO between Macs instead of on the same Mac, simply enable the Server section on one Mac and the Client on the other, and use the NSSocketPort mode on both.
Some example code from the project:
- (NSConnection *) createServerConnection
{
NSConnection * connection = nil;
id port = nil;
if([self portType] == NSSocketPortType)
{
port = [[[NSSocketPort alloc] initWithTCPPort: 0] autorelease];// random port
}
else
{
port = [NSPort port];
}
NSLog(@"Port type: %@", [port className]);
if(port)
{
connection = [[[NSConnection alloc] initWithReceivePort: port
sendPort:nil] autorelease];
if(connection)
{
id portNameServer = [self portNameServer];
if(![portNameServer registerPort: port name: PORTNAME])
{
connection = nil;
NSLog(@"registerPort:name failed");
}
}
}
return connection;
}

• While fact-based, the contents of this website is 100% opinion • All advertisements Selected By Google Ad Sense • Your Mileage May Vary • Void Where Prohibited • Do Not Try This At Home • Don’t Be An Idiot •