---
title: URLSessionWebSocketDelegate
framework: foundation
role: symbol
role_heading: Protocol
path: foundation/urlsessionwebsocketdelegate
---

# URLSessionWebSocketDelegate

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

## Declaration

```swift
protocol URLSessionWebSocketDelegate : URLSessionTaskDelegate
```

## Topics

### Handling WebSocket lifecycle events

- [urlSession(_:webSocketTask:didOpenWithProtocol:)](foundation/urlsessionwebsocketdelegate/urlsession(_:websockettask:didopenwithprotocol:).md)
- [urlSession(_:webSocketTask:didCloseWith:reason:)](foundation/urlsessionwebsocketdelegate/urlsession(_:websockettask:didclosewith:reason:).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 WebSocket tasks to a session

- [webSocketTask(with:)](foundation/urlsession/websockettask(with:)-87ipz.md)
- [webSocketTask(with:)](foundation/urlsession/websockettask(with:)-mtks.md)
- [webSocketTask(with:protocols:)](foundation/urlsession/websockettask(with:protocols:).md)
- [URLSessionWebSocketTask](foundation/urlsessionwebsockettask.md)
