<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/MessagePort",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSMessagePort"
  },
  "title" : "MessagePort"
}
-->

# MessagePort

A port that can be used as an endpoint for distributed object connections (or raw messaging).

```
class MessagePort
```

## Overview

[`MessagePort`](/documentation/Foundation/MessagePort) is a subclass of [`Port`](/documentation/Foundation/Port) that allows for local (on the same machine) communication only. A companion class, [`SocketPort`](/documentation/Foundation/SocketPort), allows for both local and remote communication, but may be more expensive than [`MessagePort`](/documentation/Foundation/MessagePort) for the local case.

[`MessagePort`](/documentation/Foundation/MessagePort) defines no additional methods over those already defined by [`Port`](/documentation/Foundation/Port).

> Note:
> ``doc://com.apple.foundation/documentation/Foundation/MessagePort`` conforms to the ``doc://com.apple.foundation/documentation/Foundation/NSCoding`` protocol, but only supports coding by an ``doc://com.apple.foundation/documentation/Foundation/NSPortCoder`` object. ``doc://com.apple.foundation/documentation/Foundation/Port`` and its subclasses do not support archiving.

> Important:
> Avoid ``doc://com.apple.foundation/documentation/Foundation/MessagePort``. There’s little reason to use ``doc://com.apple.foundation/documentation/Foundation/MessagePort`` rather than ``doc://com.apple.foundation/documentation/Foundation/NSMachPort`` or ``doc://com.apple.foundation/documentation/Foundation/SocketPort``. There’s no particular performance or functionality advantage. It is recommended avoiding its use.
> 
> ``doc://com.apple.foundation/documentation/Foundation/MessagePort`` may be deprecated in the macOS 10.6 or later.

## See Also

  [Distributed Objects Programming Topics](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/DistrObjects/DistrObjects.html#//apple_ref/doc/uid/10000102i)



---

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)