Inherits From: NSObject
Conforms To: NSObject (NSObject)
Declared In: Foundation/NSConnection.h
The NSConnection class declares the programmatic interface to objects that manage a connection such that objects in one thread can send messages to objects in another thread (typically, in another process, and it defines instances that manage each side of such a connection.
Each distinct thread of execution has one default connection defined. Any given thread can have as many connections as desired, but a given connection can be served by only one thread.
To set up a connection, some object in your application must be established as what is known as a root object and registered with a name in the Network Name Server. Such root objects can then be connected to by other threads, and can receive messages sent to them from other threads. An easy way to establish an object as a root object is to send the defaultConnection method to the NSConnection class object to obtain a connection object. Then use setRootObject: to establish the desired object as the object that will be registered, followed by registerName: to make that object available to the Network Name Server under the specified name.
To obtain a connection to an object registered elsewhere, you will generally send the rootProxyForConnectionWithRegisteredName:host: method to the NSConnection class object. This method returns a proxy to the remote object. You should then inform the proxy of the protocol(s) the remote object responds to using setProtocolForProxy:. To obtain the actual connection object instead of the proxy, use the connectionWithRegisteredName:host: method.
If the string @"*" is used where a hostname is required, it implies a lookup for any server registered with the specified name on the local subnet. If nil is supplied where a hostname is required, the name lookup occurs only on the local host.
When an NSConnection object is deallocated, the notification NSConnectionDeath is posted to the default notification center with that NSConnection object.
NSConnection can raise NSInternalInconsistencyException for a variety of reasons when it detects impossible situations. In addition, NSConnection can raise NSInvalidArgumentException when a remote method invocation sends an unknown selector.
Initializing a Connection
-(BOOL)independentConversationQueueing Returns conversationQueuing mode. The default value is NO.
If flag is YES, unrelated requests are queued for later processing. This allows a server to use distributed objects freely in its implementation without concern for the consistency of its internal state. Note that this can cause deadlocks among peers.