<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "Tor",
  "identifier" : "/documentation/Tor/HostPort",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Tor"
    ],
    "preciseIdentifier" : "s:3Tor8HostPortV"
  },
  "title" : "HostPort"
}
-->

# HostPort

Immutable `host` + `port` pair representing a TCP network endpoint.

```
struct HostPort
```

## Overview

swift-tor uses `HostPort` wherever the library crosses a TCP boundary:
the SOCKS5 proxy surfaced by [`socksEndpoint`](/documentation/Tor/TorClient/socksEndpoint), the optional
control port accepted by `TorControlClient(host:port:)`, and the
forwarding target on an [`OnionPortTarget.tcp(host:port:)`](/documentation/Tor/OnionPortTarget/tcp(host:port:)) mapping. It
is a deliberately minimal value type — a `String` + `Int` pair with
printable formatting — rather than a validating type. Address families,
DNS resolution, and port-range enforcement are deferred to the POSIX
socket layer in [`ControlSocket`](/documentation/Tor/ControlSocket) and to Apple’s CFNetwork proxy
resolver; a `HostPort` is simply a typed seat at those APIs.

The shape aligns with RFC 3986 authority components ([RFC 3986 §3.2.2](https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2))
and with SOCKS5’s host-plus-port addressing model ([RFC 1928 §4](https://datatracker.ietf.org/doc/html/rfc1928#section-4)).

> Note: `HostPort` conforms to `Sendable` (value type, all fields
> `Sendable`) and to `Hashable` (synthesised — both fields are
> `Hashable`). Equality is case- and digit-exact; `"LocalHost"` and
> `"localhost"` are distinct instances.

> Important: No validation is performed. Out-of-range ports, malformed
> IPv6 literals, and unresolvable hostnames surface as
> ``doc://Tor/documentation/Tor/TorError/ioError(_:)`` at connection time — not at construction.

## See Also

[`socksEndpoint`](/documentation/Tor/TorClient/socksEndpoint)

Tor’s local SOCKS5 proxy endpoint once start succeeds, else `nil`.

[`init(endpoint:)`](/documentation/Tor/ControlSocket/init(endpoint:))

Open a TCP connection to a typed [`HostPort`](/documentation/Tor/HostPort) endpoint.

[`OnionPortTarget`](/documentation/Tor/OnionPortTarget)

Where an onion service should forward inbound connections.

