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

Method pong

src/websockets/sync/connection.py:667–690  ·  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

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

Calls 3

send_contextMethod · 0.95
send_pongMethod · 0.80
encodeMethod · 0.45