fix: add WebSocket keepalive pings to prevent idle disconnects (#646) (#925)

This commit is contained in:
Konukhov Yaroslav authored and GitHub committed 2026-06-17 10:13:55 +03:00
1 parent 13d2b1db6d
commit 96e5b4b639
4 files changed
+34 -1

No files matched your search

+7
View File
@@ -154,6 +154,13 @@ class RawWebSocket:
self._build_frame(self.OP_BINARY, part, mask=True))
await self.writer.drain()
async def send_ping(self, payload: bytes = b''):
if self._closed:
raise ConnectionError("WebSocket closed")
frame = self._build_frame(self.OP_PING, payload, mask=True)
self.writer.write(frame)
await self.writer.drain()
async def recv(self) -> Optional[bytes]:
while not self._closed:
opcode, payload = await self._read_frame()