File size: 477 Bytes
28cd9fd
 
607d357
eabc2af
b10e518
eabc2af
 
 
 
 
 
 
607d357
eabc2af
607d357
28cd9fd
eabc2af
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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()