Send ping frame to the remote end. The data argument allows a small amount of data (up to 125 bytes) to be sent as a part of the ping message. Note that not all websocket implementations expose this data to applications. Consider using the ``websocket_ping_i
(self, data: Union[str, bytes] = b"")
| 448 | raise NotImplementedError |
| 449 | |
| 450 | def ping(self, data: Union[str, bytes] = b"") -> None: |
| 451 | """Send ping frame to the remote end. |
| 452 | |
| 453 | The data argument allows a small amount of data (up to 125 |
| 454 | bytes) to be sent as a part of the ping message. Note that not |
| 455 | all websocket implementations expose this data to |
| 456 | applications. |
| 457 | |
| 458 | Consider using the ``websocket_ping_interval`` application |
| 459 | setting instead of sending pings manually. |
| 460 | |
| 461 | .. versionchanged:: 5.1 |
| 462 | |
| 463 | The data argument is now optional. |
| 464 | |
| 465 | """ |
| 466 | data = utf8(data) |
| 467 | if self.ws_connection is None or self.ws_connection.is_closing(): |
| 468 | raise WebSocketClosedError() |
| 469 | self.ws_connection.write_ping(data) |
| 470 | |
| 471 | def on_pong(self, data: bytes) -> None: |
| 472 | """Invoked when the response to a ping frame is received.""" |