---
title: URLSessionStreamDelegate
framework: foundation
role: symbol
role_heading: Protocol
path: foundation/urlsessionstreamdelegate
---

# URLSessionStreamDelegate

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

## Declaration

```swift
protocol URLSessionStreamDelegate : URLSessionTaskDelegate
```

## Overview

Overview In addition to these methods, be sure to implement the methods in the URLSessionTaskDelegate and URLSessionDelegate protocols to handle events common to all task types and session-level events, respectively. note: A URLSession object need not have a delegate. If no delegate is assigned, a system-provided delegate is used, and you must provide a completion callback to obtain the data.

## Topics

### Handling rerouting

- [urlSession(_:betterRouteDiscoveredFor:)](foundation/urlsessionstreamdelegate/urlsession(_:betterroutediscoveredfor:).md)

### Completing stream capture

- [urlSession(_:streamTask:didBecome:outputStream:)](foundation/urlsessionstreamdelegate/urlsession(_:streamtask:didbecome:outputstream:).md)

### Handling closing events

- [urlSession(_:readClosedFor:)](foundation/urlsessionstreamdelegate/urlsession(_:readclosedfor:).md)
- [urlSession(_:writeClosedFor:)](foundation/urlsessionstreamdelegate/urlsession(_:writeclosedfor:).md)

## Relationships

### Inherits From

- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)
- [URLSessionDelegate](foundation/urlsessiondelegate.md)
- [URLSessionTaskDelegate](foundation/urlsessiontaskdelegate.md)

## See Also

### Adding stream tasks to a session

- [streamTask(withHostName:port:)](foundation/urlsession/streamtask(withhostname:port:).md)
- [streamTask(with:)](foundation/urlsession/streamtask(with:).md)
- [URLSessionStreamTask](foundation/urlsessionstreamtask.md)
