<!--
{
  "documentType" : "article",
  "framework" : "CoreFoundation",
  "identifier" : "/documentation/CoreFoundation/cfstream",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "CFStream"
}
-->

# CFStream

## Overview

This document describes the generic `CFStream` functions, data types, and constants. See also [`CFReadStream`](/documentation/CoreFoundation/CFReadStream) and [`CFWriteStream`](/documentation/CoreFoundation/CFWriteStream) for functions and constants specific to read and write streams respectively.

> Note:
> When you use the `CFStream` API for networking, read and write operations on sockets can block. To prevent blocking:
> 
> 1. Call ``doc://com.apple.corefoundation/documentation/CoreFoundation/CFReadStreamSetClient(_:_:_:_:)`` and ``doc://com.apple.corefoundation/documentation/CoreFoundation/CFWriteStreamSetClient(_:_:_:_:)`` to register to receive stream-related event notifications.
> 2. Call ``doc://com.apple.corefoundation/documentation/CoreFoundation/CFReadStreamScheduleWithRunLoop(_:_:_:)`` and ``doc://com.apple.corefoundation/documentation/CoreFoundation/CFWriteStreamScheduleWithRunLoop(_:_:_:)`` to schedule the stream on a run loop for receiving stream-related event notifications.
> 3. Call ``doc://com.apple.corefoundation/documentation/CoreFoundation/CFReadStreamOpen(_:)`` and ``doc://com.apple.corefoundation/documentation/CoreFoundation/CFWriteStreamOpen(_:)`` to open each stream.
> 4. Read only after receiving a ``doc://com.apple.corefoundation/documentation/CoreFoundation/CFStreamEventType/hasBytesAvailable`` notification. Write only after receiving a ``doc://com.apple.corefoundation/documentation/CoreFoundation/CFStreamEventType/canAcceptBytes`` notification.

## Topics

### Creating Streams

[`CFStreamCreatePairWithPeerSocketSignature`](/documentation/CoreFoundation/CFStreamCreatePairWithPeerSocketSignature(_:_:_:_:))

Creates readable and writable streams connected to a socket.

[`CFStreamCreatePairWithSocketToHost`](/documentation/CoreFoundation/CFStreamCreatePairWithSocketToHost(_:_:_:_:_:))

Creates readable and writable streams connected to a TCP/IP port of a particular host.

[`CFStreamCreatePairWithSocket`](/documentation/CoreFoundation/CFStreamCreatePairWithSocket(_:_:_:_:))

Creates readable and writable streams connected to a socket.

[`CFStreamCreateBoundPair`](/documentation/CoreFoundation/CFStreamCreateBoundPair(_:_:_:_:))

Creates a bound pair of read and write streams.

  <doc://com.apple.documentation/documentation/CFNetwork/CFStreamCreatePairWithSocketToCFHost(_:_:_:_:_:)>

  <doc://com.apple.documentation/documentation/CFNetwork/CFStreamCreatePairWithSocketToNetService(_:_:_:_:)>

### Obtaining Errors

  <doc://com.apple.documentation/documentation/CFNetwork/CFSocketStreamSOCKSGetError(_:)>

  <doc://com.apple.documentation/documentation/CFNetwork/CFSocketStreamSOCKSGetErrorSubdomain(_:)>

### Setting the Security Protocol

[`CFReadStreamSetProperty`](/documentation/CoreFoundation/CFReadStreamSetProperty(_:_:_:))

Sets the value of a property for a stream.

[`CFWriteStreamSetProperty`](/documentation/CoreFoundation/CFWriteStreamSetProperty(_:_:_:))

Sets the value of a property for a stream.

[CFStream Socket Security Level Constants](/documentation/CoreFoundation/cfstream-socket-security-level-constants)

Constants for setting the security level of a socket stream.

### Data Types

[`CFStreamError`](/documentation/CoreFoundation/CFStreamError)

The structure returned by [`CFReadStreamGetError(_:)`](/documentation/CoreFoundation/CFReadStreamGetError(_:)) and [`CFWriteStreamGetError(_:)`](/documentation/CoreFoundation/CFWriteStreamGetError(_:)).

[`CFStreamClientContext`](/documentation/CoreFoundation/CFStreamClientContext)

A structure that contains program-defined data and callbacks with which you can configure a stream’s client behavior.

### Constants

[`CFStreamStatus`](/documentation/CoreFoundation/CFStreamStatus)

Constants that describe the status of a stream.

[`CFStreamErrorDomain`](/documentation/CoreFoundation/CFStreamErrorDomain)

Defines constants for values returned in the domain field of the `CFStreamError` structure.

[CFStream Error Domain Constants (CFHost)](/documentation/CoreFoundation/cfstream-error-domain-constants-cfhost)

Defines constants for values returned in the domain field of the `CFStreamError` structure.

[Error Subdomains](/documentation/CoreFoundation/error-subdomains)

Subdomains used to determine how to interpret an error in the `kCFStreamErrorDomainSOCKS` domain.

  <doc://com.apple.documentation/documentation/CFNetwork/1518266-secure-sockets-socks-errors>

[`CFStreamEventType`](/documentation/CoreFoundation/CFStreamEventType)

Defines constants for stream-related events.

[Stream Properties](/documentation/CoreFoundation/stream-properties)

Stream property names that can be set or copied.

[CFStream Property SSL Settings Constants](/documentation/CoreFoundation/cfstream-property-ssl-settings-constants)

Constants for use in a `CFDictionary` object that is the value of the `kCFStreamPropertySSLSettings` stream property key.

[CFStream Socket Security Level Constants](/documentation/CoreFoundation/cfstream-socket-security-level-constants)

Constants for setting the security level of a socket stream.

[CFStream SOCKS Proxy Key Constants](/documentation/CoreFoundation/cfstream-socks-proxy-key-constants)

Constants for SOCKS Proxy `CFDictionary` keys.

[Stream Service Types](/documentation/CoreFoundation/stream-service-types)

String constants that specify the service type of a stream.

## See Also

  [Getting Started with Networking, Internet, and Web](https://developer.apple.com/library/archive/referencelibrary/GettingStarted/GS_NetworkingInternetWeb/_index.html#//apple_ref/doc/uid/TP40008807)

  [CFNetwork Programming Guide](https://developer.apple.com/library/archive/documentation/Networking/Conceptual/CFNetwork/Introduction/Introduction.html#//apple_ref/doc/uid/TP30001132)



---

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)