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

# init(tcpPort:)

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

```
convenience init?(tcpPort port: UInt16)
```

## Parameters

`port`

The port number for the newly created socket port to listen on. If `port` is 0, the system will assign a port number.

## Return Value

An initialized local TCP/IP socket of type `SOCK_STREAM`, listening on port `port`.

## Discussion

This method creates an IPv4 port, not an IPv6 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)