<!--
{
  "availability" : [
    "iOS: 5.0.0 - 13.0.0",
    "iPadOS: 5.0.0 - 13.0.0",
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.2.0 - 10.15.0"
  ],
  "documentType" : "symbol",
  "framework" : "Security",
  "identifier" : "/documentation/Security/SSLSetConnection(_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Security"
    ],
    "preciseIdentifier" : "c:@F@SSLSetConnection"
  },
  "title" : "SSLSetConnection(_:_:)"
}
-->

# SSLSetConnection(_:_:)

Specifies an I/O connection for a specific session.

```
func SSLSetConnection(_ context: SSLContext, _ connection: SSLConnectionRef?) -> OSStatus
```

## Parameters

`context`

An SSL session context reference.

`connection`

An SSL session connection reference. The connection data is opaque to Secure Transport; you can set it to any value that your application can use to uniquely identify the connection in the callback functions [`SSLReadFunc`](/documentation/Security/SSLReadFunc) and [`SSLWriteFunc`](/documentation/Security/SSLWriteFunc).

## Return Value

A result code. See [Secure Transport Result Codes](/documentation/Security/secure-transport-result-codes).

## Discussion

You must establish a connection before creating a secure session. After calling the [`SSLCreateContext(_:_:_:)`](/documentation/Security/SSLCreateContext(_:_:_:)) function to create an SSL session context, you call the [`SSLSetConnection(_:_:)`](/documentation/Security/SSLSetConnection(_:_:)) function to specify the connection to which the context applies. You specify a value in the `connection` parameter that your callback routines can use to identify the connection. This value might be a pointer to a socket (if you are using the Sockets API) or an endpoint (if you are using Open Transport). For example, you might create a socket, start a connection on it, create a context reference, cast the socket to an [`SSLConnectionRef`](/documentation/Security/SSLConnectionRef), and then pass both the context reference and connection reference to the [`SSLSetConnection(_:_:)`](/documentation/Security/SSLSetConnection(_:_:)) function.

Note that the Sockets API is the preferred networking interface for new development.

On the client side, it’s assumed that communication has been established with the desired server on this connection. On the server side, it’s assumed that a connection has been established in response to an incoming client request .

This function must be called prior to the [`SSLHandshake(_:)`](/documentation/Security/SSLHandshake(_:)) function; consequently, this function can be called only when no session is active.

---

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)