Skip to content

Instantly share code, notes, and snippets.

@ankitml
Created February 6, 2019 21:17
Show Gist options
  • Save ankitml/dc9310eaf7b0ae431347e8533270cba9 to your computer and use it in GitHub Desktop.
Save ankitml/dc9310eaf7b0ae431347e8533270cba9 to your computer and use it in GitHub Desktop.
Websockets Tutorial 2 - Heart Beat
import asyncio
import websockets
async def heartbeat(websocket):
while True:
await asyncio.sleep(1)
await websocket.send('💚')
async def ws_handler(websocket, path):
await heartbeat(websocket)
if __name__ == '__main__':
asyncio.get_event_loop().run_until_complete(
websockets.serve(ws_handler, '0.0.0.0', 9999),
)
asyncio.get_event_loop().run_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment