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

# 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.

```
convenience init?(remoteWithTCPPort port: UInt16, host hostName: String?)
```

## Parameters

`port`

The port to connect to.

`hostName`

The host name to connect to. `hostName` may be either a host name or an IPv4-style address.

## Return Value

A TCP/IP socket port of type `SOCK_STREAM` that can connect to the remote host `hostName` on port `port`.

## Discussion

A connection is not opened to the remote host until data is sent.

---

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)