<!--
{
  "availability" : [
    "iOS: 3.0.0 - 7.0.0",
    "iPadOS: 3.0.0 - 7.0.0",
    "macOS: 10.8.0 - 10.10.0",
    "visionOS: 1.0.0 - 1.0.0",
    "watchOS: 2.0.0 - 2.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "GameKit",
  "identifier" : "/documentation/GameKit/GKSession/connect(toPeer:withTimeout:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "GameKit"
    ],
    "preciseIdentifier" : "c:objc(cs)GKSession(im)connectToPeer:withTimeout:"
  },
  "title" : "connect(toPeer:withTimeout:)"
}
-->

# connect(toPeer:withTimeout:)

Creates a connection to another iOS device.

```
func connect(toPeer peerID: String!, withTimeout timeout: TimeInterval)
```

## Parameters

`peerID`

The string that identifies the peer to connect to.

`timeout`

The amount of time to wait before canceling the connection attempt.

## Discussion

When your application is acting as a client, it calls this method to connect to an available peer it discovered. When your application calls this method, a request is transmitted to the remote peer, who chooses whether to accept or reject the connection request.

If the connection to the remote peer is successful, the delegate’s [`session(_:peer:didChange:)`](/documentation/GameKit/GKSessionDelegate/session(_:peer:didChange:)) method is called for each peer it successfully connected to. If the connection fails or your application cancels the connection attempt, the session calls the delegate’s [`session(_:connectionWithPeerFailed:withError:)`](/documentation/GameKit/GKSessionDelegate/session(_:connectionWithPeerFailed:withError:)) method.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)