Skip to content

You're viewing documentation for a pre-release version. View the latest stable version

Initializer

init(ipAddress:port:)

Creates an address from an IP literal, returning nil if ipAddress is not one.
init?(ipAddress: String, port: Int)

Parameters

ipAddress

A dotted-quad IPv4 literal, or an IPv6 literal without a zone index.

port

The port, stored as given and not range-checked.

Discussion

Only literals are accepted — a hostname is never resolved, so this never performs I/O and is safe to call on any thread. Which of SocketAddress.Kind.ipv4 or SocketAddress.Kind.ipv6 results is decided by the literal itself.

Parsing is deliberately stricter than the platform’s inet_pton: octets with leading zeros and IPv6 zone indices are both refused, so the same string is accepted or rejected identically on every platform Vapor runs on.