First code
This commit is contained in:
parent
1ce94580ff
commit
3587d0184f
4 changed files with 38 additions and 0 deletions
22
server/chatserver.py
Executable file
22
server/chatserver.py
Executable 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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue