MCPcopy Create free account
hub / github.com/python-websockets/websockets / pong

Method pong

src/websockets/asyncio/connection.py:718–741  ·  view source on GitHub ↗

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"")

Source from the content-addressed store, hash-verified

716 return pong_received
717
718 async def pong(self, data: DataLike = b"") -> None:
719 """
720 Send a Pong_.
721
722 .. _Pong: https://datatracker.ietf.org/doc/html/rfc6455#section-5.5.3
723
724 An unsolicited pong may serve as a unidirectional heartbeat.
725
726 Args:
727 data: Payload of the pong. A :class:`str` will be encoded to UTF-8.
728
729 Raises:
730 ConnectionClosed: When the connection is closed.
731
732 """
733 if isinstance(data, BytesLike):
734 data = bytes(data)
735 elif isinstance(data, str):
736 data = data.encode()
737 else:
738 raise TypeError("data must be str or bytes-like")
739
740 async with self.send_context():
741 self.protocol.send_pong(data)
742
743 # Private methods
744

Callers

nothing calls this directly

Calls 3

send_contextMethod · 0.95
send_pongMethod · 0.80
encodeMethod · 0.45

Tested by

no test coverage detected