---
title: "CFSocketConnectToAddress(_:_:_:)"
framework: corefoundation
role: symbol
role_heading: Function
path: "corefoundation/cfsocketconnecttoaddress(_:_:_:)"
---

# CFSocketConnectToAddress(_:_:_:)

Opens a connection to a remote socket.

## Declaration

```swift
func CFSocketConnectToAddress(_ s: CFSocket!, _ address: CFData!, _ timeout: CFTimeInterval) -> CFSocketError
```

## Parameters

- `s`: The CFSocket object with which to connect to address.
- `address`: A CFData object containing a struct sockaddr appropriate for the protocol family of s (struct sockaddr_in or struct sockaddr_in6, for example), indicating the remote address to which to connect. This data object is used only for the duration of the function call.
- `timeout`: The time to wait for a connection to succeed. If a negative value is used, this function does not wait for the connection and instead lets the connection attempt happen in the background. If s requested a kCFSocketConnectCallBack, you will receive a callback when the background connection succeeds or fails.

## Return Value

Return Value An error code indicating success or failure of the connection attempt.

## See Also

### Using Sockets

- [CFSocketCreateRunLoopSource(_:_:_:)](corefoundation/cfsocketcreaterunloopsource(_:_:_:).md)
- [CFSocketGetTypeID()](corefoundation/cfsocketgettypeid().md)
- [CFSocketInvalidate(_:)](corefoundation/cfsocketinvalidate(_:).md)
- [CFSocketIsValid(_:)](corefoundation/cfsocketisvalid(_:).md)
- [CFSocketSendData(_:_:_:_:)](corefoundation/cfsocketsenddata(_:_:_:_:).md)
