<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "Event",
  "identifier" : "/documentation/Event/Socket/connect(to:port:loop:timeout:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Event"
    ],
    "preciseIdentifier" : "s:5Event6SocketC7connect2to4port4loop7timeoutACSS_s6UInt16VAA0A4LoopCs8DurationVSgtYaKFZ"
  },
  "title" : "connect(to:port:loop:timeout:)"
}
-->

# 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`](/documentation/Event/EventLoop/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`](/documentation/Event/SocketError/timeout).

## Return Value

A connected `Socket` ready for [`read(maxBytes:timeout:)`](/documentation/Event/Socket/read(maxBytes:timeout:)) / [`write(_:timeout:)`](/documentation/Event/Socket/write(_:timeout:)).

## Discussion

Convenience shorthand that parses `host` via [`ipv4(_:port:)`](/documentation/Event/SocketAddress/ipv4(_:port:)) and
delegates to [`connect(to:loop:timeout:)`](/documentation/Event/Socket/connect(to:loop:timeout:)). For IPv6 endpoints or pre-parsed
addresses, use [`connect(to:loop:timeout:)`](/documentation/Event/Socket/connect(to:loop:timeout:)) directly.

> Throws: ``doc://Event/documentation/Event/SocketError/invalidAddress(_:)``,
> ``doc://Event/documentation/Event/SocketError/socketCreationFailed(_:)``,
> ``doc://Event/documentation/Event/SocketError/connectionFailed(_:)``, or ``doc://Event/documentation/Event/SocketError/timeout``.