<!--
{
  "availability" : [
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.0.0 - 10.13.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSConnection",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSConnection"
  },
  "title" : "NSConnection"
}
-->

# NSConnection

An object that manages the communication between objects in different threads or between a thread and a process running on a local or remote system.

```
@interface NSConnection : NSObject
```

## Overview

Connection objects form the backbone of the distributed objects mechanism and normally operate in the background. You use the methods of [`NSConnection`](/documentation/Foundation/NSConnection) explicitly when vending an object to other applications, when accessing such a vended object through a proxy, and when altering default communication parameters. At other times, you simply interact with a vended object or its proxy.

A single connection object may be shared by multiple threads and used to access a vended object.

## Topics

### Getting the Default Instance

[`+  defaultConnection`](/documentation/Foundation/NSConnection/defaultConnection)

Returns the default `NSConnection` object for the current thread.

### Creating Instances

[`+  connectionWithReceivePort:sendPort:`](/documentation/Foundation/NSConnection/connectionWithReceivePort:sendPort:)

Returns an `NSConnection` object that communicates using given send and receive ports.

[`-  initWithReceivePort:sendPort:`](/documentation/Foundation/NSConnection/initWithReceivePort:sendPort:)

Returns an `NSConnection` object initialized with given send and receive ports.

### Running the Connection in a New Thread

[`-  runInNewThread`](/documentation/Foundation/NSConnection/runInNewThread)

Creates and starts a new `NSThread` object and then runs the receiving connection in the new thread.

[`-  enableMultipleThreads`](/documentation/Foundation/NSConnection/enableMultipleThreads)

Configures the receiver to allow requests from multiple threads to the remote object, without requiring each thread to each maintain its own connection.

[`multipleThreadsEnabled`](/documentation/Foundation/NSConnection/multipleThreadsEnabled)

A Boolean value that indicates whether the receiver supports requests from multiple threads.

[`-  addRunLoop:`](/documentation/Foundation/NSConnection/addRunLoop:)

Adds the specified run loop to the list of run loops the receiver monitors and from which it responds to requests.

[`-  removeRunLoop:`](/documentation/Foundation/NSConnection/removeRunLoop:)

Removes a given `NSRunLoop` object from the list of run loops the receiver monitors and from which it responds to requests.

### Vending a Service

[`+  serviceConnectionWithName:rootObject:usingNameServer:`](/documentation/Foundation/NSConnection/serviceConnectionWithName:rootObject:usingNameServer:)

Creates and returns a new connection object representing a vended service on the specified port name server.

[`+  serviceConnectionWithName:rootObject:`](/documentation/Foundation/NSConnection/serviceConnectionWithName:rootObject:)

Creates and returns a new connection object representing a vended service on the default system port name server.

[`-  registerName:`](/documentation/Foundation/NSConnection/registerName:)

Registers the specified service using with the default system port name server.

[`-  registerName:withNameServer:`](/documentation/Foundation/NSConnection/registerName:withNameServer:)

Registers a service with the specified port name server.

[`rootObject`](/documentation/Foundation/NSConnection/rootObject-c.property)

The object that the receiver (or its parent) makes available to other applications or threads.

### Getting a Remote Object

[`+  connectionWithRegisteredName:host:`](/documentation/Foundation/NSConnection/connectionWithRegisteredName:host:)

Returns the `NSConnection` object whose send port links it to the `NSConnection` object registered with the default `NSPortNameServer` under a given name on a given host.

[`+  connectionWithRegisteredName:host:usingNameServer:`](/documentation/Foundation/NSConnection/connectionWithRegisteredName:host:usingNameServer:)

Returns the `NSConnection` object whose send port links it to the `NSConnection` object registered under a given name with a given server on a given host.

[`rootProxy`](/documentation/Foundation/NSConnection/rootProxy)

The proxy for the root object of the receiver’s peer in another application or thread.

[`+  rootProxyForConnectionWithRegisteredName:host:`](/documentation/Foundation/NSConnection/rootProxyForConnectionWithRegisteredName:host:)

Returns a proxy for the root object of the `NSConnection` object registered with the default `NSPortNameServer` under a given name on a given host.

[`+  rootProxyForConnectionWithRegisteredName:host:usingNameServer:`](/documentation/Foundation/NSConnection/rootProxyForConnectionWithRegisteredName:host:usingNameServer:)

Returns a proxy for the root object of the `NSConnection` object registered with `server` under `name` on a given host.

[`remoteObjects`](/documentation/Foundation/NSConnection/remoteObjects)

The local proxies for remote objects that have been received over the connection but not deallocated yet.

[`localObjects`](/documentation/Foundation/NSConnection/localObjects)

The local objects that have been sent over the connection and still have proxies at the other end.

### Getting a Conversation

[`+  currentConversation`](/documentation/Foundation/NSConnection/currentConversation)

Returns a token object representing any conversation in progress in the current thread.

### Getting All NSConnection Objects

[`+  allConnections`](/documentation/Foundation/NSConnection/allConnections)

Returns all valid `NSConnection` objects in the process.

### Configuring Instances

[`requestTimeout`](/documentation/Foundation/NSConnection/requestTimeout)

The timeout interval for outgoing remote messages.

[`replyTimeout`](/documentation/Foundation/NSConnection/replyTimeout)

The timeout interval for replies to outgoing remote messages.

[`independentConversationQueueing`](/documentation/Foundation/NSConnection/independentConversationQueueing)

A Boolean value that indicates whether the receiver handles remote messages atomically.

[`-  addRequestMode:`](/documentation/Foundation/NSConnection/addRequestMode:)

Adds `mode` to the set of run-loop input modes that the receiver uses for connection requests.

[`-  removeRequestMode:`](/documentation/Foundation/NSConnection/removeRequestMode:)

Removes `mode` from the set of run-loop input modes the receiver uses for connection requests.

[`requestModes`](/documentation/Foundation/NSConnection/requestModes-c.property)

The set of request modes the receiver’s receive port is registered for with its `NSRunLoop` object.

[`-  invalidate`](/documentation/Foundation/NSConnection/invalidate)

Invalidates the receiver.

[`valid`](/documentation/Foundation/NSConnection/valid)

A Boolean value that indicates whether the receiver is known to be valid.

### Getting Ports

[`receivePort`](/documentation/Foundation/NSConnection/receivePort-c.property)

The port on which the receiver receives incoming network messages.

[`sendPort`](/documentation/Foundation/NSConnection/sendPort-c.property)

The port that the connection sends outgoing network messages through.

[`-  dispatchWithComponents:`](/documentation/Foundation/NSConnection/dispatchWithComponents:)

Allows subclasses to ask a connection object to dispatch component data.

### Getting Statistics

[`statistics`](/documentation/Foundation/NSConnection/statistics-c.property)

A dictionary containing various statistics for the receiver.

### Setting the Delegate

[`delegate`](/documentation/Foundation/NSConnection/delegate-c.property)

The receiver’s delegate.

### Constants

[NSConnection run loop mode](/documentation/Foundation/nsconnection-run-loop-mode)

`NSConnection` defines the following run loop mode—see [`RunLoop`](/documentation/Foundation/RunLoop) for more details.

[Connection Exception Names](/documentation/Foundation/connection-exception-names)

The name of an exception raised in case of authentication failure.

### Notifications

[`NSConnectionDidDieNotification`](/documentation/Foundation/NSConnectionDidDieNotification)

Posted when an `NSConnection` object is deallocated or when it’s notified that its `NSPort` object has become invalid. The notification object is the `NSConnection` object. This notification does not contain a `userInfo` dictionary.

[`NSConnectionDidInitializeNotification`](/documentation/Foundation/NSConnectionDidInitializeNotification)

Posted when an `NSConnection` object is initialized using [`initWithReceivePort:sendPort:`](/documentation/Foundation/NSConnection/initWithReceivePort:sendPort:) (the designated initializer for `NSConnection`). The notification object is the `NSConnection` object. This notification does not contain a `userInfo` dictionary.

## Relationships

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)