Retired Document
Important: This document may not represent best practices for current development. Links to downloads and other resources may no longer be valid.
For interprocess communication, you should use XPC instead; see XPC Services API Reference for more information.
About Distributed Objects
Cocoa’s distributed objects architecture enables objects in different threads or tasks, perhaps on different machines, to transparently send messages to each other. While there are many ways for threads and tasks to communicate with one another, distributed objects hides the mechanism behind the standard Objective-C messaging mechanism. The syntax of local and remote messages are identical.
Remote messages can be sent synchronously or asynchronously. When sending a synchronous message, the sender waits for a reply, blocking its execution, just like a local message. When sending an asynchronous message, the sender continues executing without waiting for a reply; any response from the remote object is ignored.
Distributed objects can be used to divide a complex task into separate code paths that run independently, but can still cooperate as if they were running together. For example, an application can be divided into a graphical front end and a computational back end. The front end can accept all user input and tell the back end to perform various actions. The back end can handle the “heavy lifting” and inform the front end when it can update the user interface with the results. Because the front and back ends run independently, the front end can continue interacting with the user while the back end is busy.
Distributed objects can also be used to implement distributed computing, or parallel processing. If a large job is split into many smaller jobs that are distributed on a multiprocessor machine or on multiple machines, you can harness the combined computational power of all the processors to complete the job. Distributed objects simplifies the application architecture and the communication between its distributed parts.
Cocoa allows distributed objects to communicate over Mach ports, message ports, and sockets. The first two are restricted to communication on a single machine, but sockets can communicate over large networks, including the internet.
Before an object can receive messages from other processes, it must allocate a communication port and make it available to others. Cocoa provides access to name servers for each supported type of communication port. An object can register its port with the appropriate name server to allow other processes to find it. In the case of sockets, you can also publish the object’s socket as a Bonjour network service (see the Cocoa Programming Topic Bonjour Overview). Other processes that want to communicate with this object can then look up the object’s communication port, requesting it by name, and attach distributed object connections to it.
For details on how the Objective-C language and runtime enables distributed objects, see the “Remote Messaging” section of The Runtime System in The Objective-C Programming Language.
Copyright © 2003, 2017 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2017-06-07