<!--
{
  "availability" : [
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/SocketPort/init(protocolFamily:socketType:protocol:address:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSSocketPort(im)initWithProtocolFamily:socketType:protocol:address:"
  },
  "title" : "init(protocolFamily:socketType:protocol:address:)"
}
-->

# init(protocolFamily:socketType:protocol:address:)

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

```
init?(protocolFamily family: Int32, socketType type: Int32, protocol: Int32, address: Data)
```

## Parameters

`family`

The protocol family for the socket port. Possible values are defined in `<sys/socket.h>`, such as `AF_LOCAL`, `AF_INET`, and `AF_INET6`.

`type`

The type of socket.

`protocol`

The specific protocol to use from the protocol family.

`address`

The family-specific socket address for the receiver copied into an `NSData` object.

## Return Value

A local socket port initialized with the provided arguments.

## Discussion

The receiver must be added to a run loop before it can accept connections or receive messages. Incoming messages are passed to the receiver’s delegate method handlePortMessage:.

To create a standard TCP/IP socket, use [`init(tcpPort:)`](/documentation/Foundation/SocketPort/init(tcpPort:)-6hgbo).

---

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)