Type Method
connect(to:port:loop:timeout:)
Connects to a remote IPv4 host by numeric address.
static func connect(to host: String, port: UInt16, loop: EventLoop = .shared, timeout: Duration? = nil) async throws -> Socket
Parameters
-
host
-
Numeric IPv4 address (DNS names are not resolved).
-
port
-
TCP port in host byte order.
-
loop
-
The event loop to drive. Defaults to shared.
-
timeout
-
Maximum time to wait for the kernel to complete the handshake. nil (the default) waits indefinitely. On expiry the call throws SocketError.timeout.
Return Value
A connected Socket ready for read(maxBytes:timeout:) / write(_:timeout:).
Mentioned In
Discussion
Convenience shorthand that parses host via ipv4(_:port:) and delegates to connect(to:loop:timeout:). For IPv6 endpoints or pre-parsed addresses, use connect(to:loop:timeout:) directly.
Throws
SocketError.invalidAddress(_:), SocketError.socketCreationFailed(_:), SocketError.connectionFailed(_:), or SocketError.timeout.