<!--
{
  "availability" : [

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

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

## Return Value

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

## Discussion

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

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