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

# SocketPort

A port that represents a BSD socket.

```
class SocketPort
```

## Overview

A [`SocketPort`](/documentation/Foundation/SocketPort) object can be used as an endpoint for distributed object connections. Companion classes, [`NSMachPort`](/documentation/Foundation/NSMachPort) and [`MessagePort`](/documentation/Foundation/MessagePort), allow for local (on the same machine) communication only. The [`SocketPort`](/documentation/Foundation/SocketPort) class allows for both local and remote communication, but may be more expensive than the others for the local case.

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

## Topics

### Creating Instances

[`-  init`](/documentation/Foundation/SocketPort/init())

Initializes the receiver as a local TCP/IP socket of type `SOCK_STREAM`.

[`-  initWithTCPPort:`](/documentation/Foundation/SocketPort/init(tcpPort:)-6hgbo)

Initializes the receiver as a local TCP/IP socket of type `SOCK_STREAM`, listening on a specified port number.

[`-  initWithProtocolFamily:socketType:protocol:address:`](/documentation/Foundation/SocketPort/init(protocolFamily:socketType:protocol:address:))

Initializes the receiver as a local socket with the provided arguments.

[`-  initWithProtocolFamily:socketType:protocol:socket:`](/documentation/Foundation/SocketPort/init(protocolFamily:socketType:protocol:socket:))

Initializes the receiver with a previously created local socket.

[`-  initRemoteWithTCPPort:host:`](/documentation/Foundation/SocketPort/init(remoteWithTCPPort:host:))

Initializes the receiver as a TCP/IP socket of type `SOCK_STREAM` that can connect to a remote host on a specified port.

[`-  initRemoteWithProtocolFamily:socketType:protocol:address:`](/documentation/Foundation/SocketPort/init(remoteWithProtocolFamily:socketType:protocol:address:))

Initializes the receiver as a remote socket with the provided arguments.

### Getting Information

[`address`](/documentation/Foundation/SocketPort/address)

The receiver’s socket address structure stored inside an [`NSData`](/documentation/Foundation/NSData) object.

[`protocol`](/documentation/Foundation/SocketPort/protocol)

The protocol that the receiver uses for communication.

[`protocolFamily`](/documentation/Foundation/SocketPort/protocolFamily)

The protocol family that the receiver uses for communication.

[`socket`](/documentation/Foundation/SocketPort/socket)

The receiver’s native socket identifier on the platform.

[`socketType`](/documentation/Foundation/SocketPort/socketType)

The receiver’s socket type.

## Relationships

### Conforms To

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Sendable`](/documentation/Swift/Sendable)

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

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

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CVarArg`](/documentation/Swift/CVarArg)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Hashable`](/documentation/Swift/Hashable)

[`Equatable`](/documentation/Swift/Equatable)

### Inherits From

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

---

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)