Type Method
connect(to:port:loop:)
Connects to a remote IPv4 host by numeric address.
static func connect(to host: String, port: UInt16, loop: EventLoop = .shared) 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.
Return Value
A connected Socket ready for read(maxBytes:) / write(_:).
Mentioned In
Discussion
Convenience shorthand that parses host via ipv4(_:port:) and delegates to connect(to:loop:). For IPv6 endpoints or pre-parsed addresses, use connect(to:loop:) directly.
Throws
SocketError.invalidAddress(_:), SocketError.socketCreationFailed(_:), or SocketError.connectionFailed(_:).