Last active
May 28, 2022 04:33
-
-
Save GitHub30/3200edfb70a537064e8df7dce84e1375 to your computer and use it in GitHub Desktop.
pip install websockets
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
#!/usr/bin/env python | |
import asyncio | |
import websockets | |
connected = set() | |
async def broadcast(websocket): | |
connected.add(websocket) | |
async for message in websocket: | |
websockets.broadcast(connected, message) | |
async def main(): | |
async with websockets.serve(broadcast, "localhost", 8765): | |
await asyncio.Future() # run forever | |
asyncio.run(main()) |
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
echo '#!/usr/bin/env python | |
import asyncio | |
import websockets | |
connected = set() | |
async def broadcast(websocket): | |
connected.add(websocket) | |
async for message in websocket: | |
websockets.broadcast(connected, message) | |
async def main(): | |
async with websockets.serve(broadcast, "localhost", 8765): | |
await asyncio.Future() # run forever | |
asyncio.run(main())' | python3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment