diff --git a/aiohttp_sse/__init__.py b/aiohttp_sse/__init__.py index a696b9a..ea36987 100644 --- a/aiohttp_sse/__init__.py +++ b/aiohttp_sse/__init__.py @@ -198,10 +198,11 @@ async def _ping(self) -> None: # periodically send ping to the browser. Any message that # starts with ":" colon ignored by a browser and could be used # as ping message. + message = ": ping{0}{0}".format(self._sep).encode("utf-8") while True: await asyncio.sleep(self._ping_interval) try: - await self.write(": ping{0}{0}".format(self._sep).encode("utf-8")) + await self.write(message) except (ConnectionResetError, RuntimeError): # RuntimeError - on writing after EOF break