First code

This commit is contained in:
Lexi / Zoe 2018-10-27 04:36:09 +02:00
parent 1ce94580ff
commit 3587d0184f
4 changed files with 38 additions and 0 deletions

22
server/chatserver.py Executable file
View file

@ -0,0 +1,22 @@
#!/usr/bin/env python
# Example code from:
# https://websockets.readthedocs.io/en/stable/intro.html
import asyncio
import websockets
async def hello(websocket, path):
name = await websocket.recv()
print(f"< {name}")
greeting = f"Hello {name}!"
await websocket.send(greeting)
print(f"> {greeting}")
start_server = websockets.serve(hello, 'localhost', 8765)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()