---
title: "webSocketTask(with:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/urlsession/websockettask(with:)-87ipz"
---

# webSocketTask(with:)

Creates a WebSocket task for the provided URL.

## Declaration

```swift
func webSocketTask(with url: URL) -> URLSessionWebSocketTask
```

## Parameters

- `url`: The WebSocket URL with which to connect.

## Discussion

Discussion The provided URL must have a ws or wss scheme.

## See Also

### Adding WebSocket tasks to a session

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