Class

URLSessionStreamTask

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

Overview

The NSURLSessionStreamTask class provides an interface a TCP/IP connection created via URLSession. Tasks may be created from an NSURLSession using the streamTask(withHostName:port:) and streamTask(with:) methods. They may also created as a result of an URLSessionDataTask being upgraded via the HTTP Upgrade: response header and appropriate use of the httpShouldUsePipelining option of URLSessionConfiguration.

An NSURLSessionStreamTask object perform asynchronous 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 Stream objects, you can create InputStream and OutputStream objects from an NSURLSessionStreamTask object by calling the captureStreams() method.

Symbols

Reading and Writing Data

func readData(ofMinLength: Int, maxLength: Int, timeout: TimeInterval, completionHandler: (Data?, Bool, Error?) -> Void)

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

func write(Data, timeout: TimeInterval, completionHandler: (Error?) -> Void)

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

Capturing Streams

func captureStreams()

Completes any already enqueued reads and writes, and then invokes the urlSession(_:streamTask:didBecome:outputStream:) delegate message.

Closing Read and Write Sockets

func closeRead()

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

func closeWrite()

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

Starting and Stopping Secure Connections

func startSecureConnection()

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

func stopSecureConnection()

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

Relationships

Inherits From

Conforms To