<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "Tor",
  "identifier" : "/documentation/Tor/TorControlClient/init(host:port:dataDirectory:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Tor"
    ],
    "preciseIdentifier" : "s:3Tor0A13ControlClientC4host4port13dataDirectoryACSS_SiSSSgtKcfc"
  },
  "title" : "init(host:port:dataDirectory:)"
}
-->

# init(host:port:dataDirectory:)

Open a TCP connection to a listening Tor control port and wrap
it.

```
convenience init(host: String, port: Int, dataDirectory: String? = nil) throws
```

## Parameters

`host`

IPv4 literal or DNS name of the control-port host.

`port`

TCP port (typically 9051).

`dataDirectory`

Optional path to the daemon’s data
directory, used by [`authenticate(password:)`](/documentation/Tor/TorControlClient/authenticate(password:)) for
cookie-based authentication.

## Discussion

Convenience for the external-Tor scenario: an already-running
`tor` daemon is exposing its control port over TCP (typically
`127.0.0.1:9051`) and swift-tor wants to drive it. The
underlying [`ControlSocket`](/documentation/Tor/ControlSocket) owns the FD and closes it on
`deinit`.

> Throws: ``doc://Tor/documentation/Tor/TorError/ioError(_:)`` on socket/connect/DNS
> failure propagated from ``doc://Tor/documentation/Tor/ControlSocket/init(host:port:)``.

> Important: The resulting client is **not authenticated**.
> Call ``doc://Tor/documentation/Tor/TorControlClient/authenticate(password:)`` before any other command.