---
title: "init(tcpPort:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/socketport/init(tcpport:)-6hgbo"
---

# init(tcpPort:)

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

## Declaration

```swift
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

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

## Discussion

Discussion This method creates an IPv4 port, not an IPv6 port.

## See Also

### Creating Instances

- [init()](foundation/socketport/init().md)
- [init(protocolFamily:socketType:protocol:address:)](foundation/socketport/init(protocolfamily:sockettype:protocol:address:).md)
- [init(protocolFamily:socketType:protocol:socket:)](foundation/socketport/init(protocolfamily:sockettype:protocol:socket:).md)
- [init(remoteWithTCPPort:host:)](foundation/socketport/init(remotewithtcpport:host:).md)
- [init(remoteWithProtocolFamily:socketType:protocol:address:)](foundation/socketport/init(remotewithprotocolfamily:sockettype:protocol:address:).md)
