Image7 / app.py
clone3's picture
Update app.py
eabc2af verified
raw
history blame contribute delete
477 Bytes
import asyncio
import websockets
clients = set()
async def chat_server(websocket, path):
clients.add(websocket)
try:
async for message in websocket:
await asyncio.wait([client.send(message) for client in clients if client != websocket])
finally:
clients.remove(websocket)
start_server = websockets.serve(chat_server, "localhost", 7860)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()