Class

NSURLSessionStreamTask

A URL session task that is stream-based.

Declaration

@interface NSURLSessionStreamTask : NSURLSessionTask

Overview

NSURLSessionStreamTask is a concrete subclass of NSURLSessionTask. Many of the methods in the NSURLSessionStreamTask class are documented in NSURLSessionTask.

The NSURLSessionStreamTask class provides an interface a TCP/IP connection created via NSURLSession. Tasks may be created from an NSURLSession using the streamTaskWithHostName:port: and streamTaskWithNetService: methods. They may also created as a result of an NSURLSessionDataTask being upgraded via the HTTP Upgrade: response header and appropriate use of the HTTPShouldUsePipelining option of NSURLSessionConfiguration.

An NSURLSessionStreamTask object perform sasynchronous reads and writes, which are enqueued and executed serially, calling a handler upon completion being on the session delegate queue. If the task is canceled, all enqueued reads and writes will call their completion handlers with an appropriate error.

When working with APIs that accept NSStream objects, you can create NSInputStream and NSOutputStream objects from an NSURLSessionStreamTask object by calling the captureStreams method.

Topics

Reading and Writing Data

- readDataOfMinLength:maxLength:timeout:completionHandler:

Asynchronously reads a number of bytes from the stream, and calls a handler upon completion.

- writeData:timeout:completionHandler:

Asynchronously writes the specified data to the stream, and calls a handler upon completion.

Capturing Streams

- captureStreams

Completes any already enqueued reads and writes, and then invokes the URLSession:streamTask:didBecomeInputStream:outputStream: delegate message.

Closing Read and Write Sockets

- closeRead

Completes any enqueued reads and writes, and then closes the read side of the underlying socket.

- closeWrite

Completes any enqueued reads and writes, and then closes the write side of the underlying socket.

Starting and Stopping Secure Connections

- startSecureConnection

Completes any enqueued reads and writes, and establishes a secure connection.

- stopSecureConnection

Completes any enqueued reads and writes, and closes the secure connection.

Relationships

Inherits From

See Also

Adding Stream Tasks to a Session

- streamTaskWithHostName:port:

Creates a task that establishes a bidirectional TCP/IP connection to a specified hostname and port.

- streamTaskWithNetService:

Creates a task that establishes a bidirectional TCP/IP connection using a specified network service.

NSURLSessionStreamDelegate

A protocol defining methods that URL session instances call on their delegates to handle task-level events specific to stream tasks.