Send a Pong_. .. _Pong: https://datatracker.ietf.org/doc/html/rfc6455#section-5.5.3 An unsolicited pong may serve as a unidirectional heartbeat. Args: data: Payload of the pong. A :class:`str` will be encoded to UTF-8. Raises: Conn
(self, data: DataLike = b"")
| 665 | return pong_received |
| 666 | |
| 667 | def pong(self, data: DataLike = b"") -> None: |
| 668 | """ |
| 669 | Send a Pong_. |
| 670 | |
| 671 | .. _Pong: https://datatracker.ietf.org/doc/html/rfc6455#section-5.5.3 |
| 672 | |
| 673 | An unsolicited pong may serve as a unidirectional heartbeat. |
| 674 | |
| 675 | Args: |
| 676 | data: Payload of the pong. A :class:`str` will be encoded to UTF-8. |
| 677 | |
| 678 | Raises: |
| 679 | ConnectionClosed: When the connection is closed. |
| 680 | |
| 681 | """ |
| 682 | if isinstance(data, BytesLike): |
| 683 | data = bytes(data) |
| 684 | elif isinstance(data, str): |
| 685 | data = data.encode() |
| 686 | else: |
| 687 | raise TypeError("data must be str or bytes-like") |
| 688 | |
| 689 | with self.send_context(): |
| 690 | self.protocol.send_pong(data) |
| 691 | |
| 692 | # Private methods |
| 693 |