Introduction to Stream Programming Guide for Cocoa
A stream is a fundamental abstraction in programming: a sequence of bits transmitted serially from one point to another point. Cocoa provides three classes to represent streams and facilitate their use in your programs: NSStream, NSInputStream, and NSOutputStream. With the instances of these classes you can read data from, and write data to, files and application memory. You can also use these objects in socket-based connections to exchange data with remote hosts. You can also subclass the stream classes to obtain specialized stream behavior.
Organization of This Document
This document includes the following articles:
Cocoa Streams gives an overview of the Cocoa stream classes, describing architecture, capabilities, and general usage.
Reading From Input Streams explains how to create and prepare a (non-socket) input-stream object. It also describes how to handle stream events generated by all types of NSInputStream objects.
Writing To Output Streams explains how to create and prepare a (non-socket) output-stream object. It also describes how to handle stream events generated by all types of NSOutputStream objects.
Polling Versus Run-Loop Scheduling discusses the relative merits of the two techniques used to avoid blocking when reading and writing to streams. It also illustrates how to poll for stream data using the API of the stream classes.
Handling Stream Errors describes how to handle errors that occur in stream processing.
Setting Up Socket Streams explains how to set up stream objects used to communicate with remote hosts via sockets.
You may find the following external resources helpful if you are implementing socket-based network streams:
OpenSSL — http://www.openssl.org/
Apache SSL — http://www.apache-ssl.org/