This repository has been archived on 2024-04-03. You can view files and clone it, but cannot push or open issues or pull requests.
OLD-GZod01.fr_Source_Code-OLD/main-site/chat/server.py

38 lines
649 B
Python
Raw Permalink Normal View History

2023-03-25 09:29:34 +00:00
"""
message templates:
{
"name":username,
"content":content,
"date":date,
}
"""
import asyncio;
import json;
import websockets;
dataslist = []
async def handler(websocket, path):
global dataslist
data = await websocket.recv()
try:
data = json.dumps(data)
except TypeError:
await websocket.send('TypeError')
await websocket.send(str(dataslist))
dataslist.append(data)
start_server = websockets.serve(handler, "0.0.0.0", 8000)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()