<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URLSessionWebSocketTask/sendPing(pongReceiveHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURLSessionWebSocketTask(im)sendPingWithPongReceiveHandler:"
  },
  "title" : "sendPing(pongReceiveHandler:)"
}
-->

# sendPing(pongReceiveHandler:)

Sends a ping frame from the client side, with a closure to receive the pong from the server endpoint.

```
func sendPing(pongReceiveHandler: @escaping @Sendable ((any Error)?) -> Void)
```

## Parameters

`pongReceiveHandler`

A closure called by the task when it receives the pong from the server. The block/closure receives an [`NSError`](/documentation/Foundation/NSError) that indicates a lost connection or other problem, or `nil` if no error occurred.

## Discussion

When sending multiple pings, the task always calls `pongReceiveHandler` in the order it sent the pings.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)