NSConnection object can be assigned a delegate, which has two possible responsibilities: approving the formation of new connections, and authenticating messages that pass between
When a named
NSConnection object is contacted by a client and forms a child
NSConnection object to communicate with that client, it sends
connection:shouldMakeNewConnection: to its delegate first to approve the new connection. If the delegate returns
NO the connection is refused. This method is useful for limiting the load on a server. It’s also useful for setting the delegate of a child
NSConnection object (since delegates are not shared automatically between parent and child).
Portable Distributed Objects adds message authentication to
NSConnection’s API. Delegates in different applications can cooperate to validate the messages passing between them by implementing
authenticateComponents:withData:. The first method requests an authentication stamp for an outgoing message, which is used by the second method to check the validity of the message when it is received.
authenticationDataForComponents: provides the packaged components for an outgoing network message in the form of
NSPort objects. The delegate should use only the
NSData objects to create the authentication stamp, by hashing the data, calculating a checksum, or some other method. The stamp should be small enough not to adversely affect network performance. The delegate in the receiving application receives an
authenticateComponents:withData: message to confirm the message, and should recalculate the stamp for the components and compare it with the stamp provided. If it returns
YES the message is forwarded; if it returns
NSFailedAuthenticationException is raised and a message is logged to the console.