Created
February 6, 2019 21:17
-
-
Save ankitml/dc9310eaf7b0ae431347e8533270cba9 to your computer and use it in GitHub Desktop.
Websockets Tutorial 2 - Heart Beat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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