---
title: "send(_:completionHandler:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/urlsessionwebsockettask/send(_:completionhandler:)"
---

# send(_:completionHandler:)

Sends a WebSocket message, receiving the result in a completion handler.

## Declaration

```swift
@preconcurrency func send(_ message: URLSessionWebSocketTask.Message, completionHandler: @escaping @Sendable ((any Error)?) -> Void)
```

## Parameters

- `message`: The WebSocket message to send to the other endpoint.
- `completionHandler`: A closure that receives an doc://com.apple.foundation/documentation/Foundation/NSError that indicates an error encountered while sending, or nil if no error occurred.

## Discussion

Discussion If an error occurs while sending the message, any outstanding work also fails.

## See Also

### Sending and receiving data

- [URLSessionWebSocketTask.Message](foundation/urlsessionwebsockettask/message.md)
- [receive(completionHandler:)](foundation/urlsessionwebsockettask/receive(completionhandler:).md)
- [maximumMessageSize](foundation/urlsessionwebsockettask/maximummessagesize.md)
