23 lines
464 B
Python
23 lines
464 B
Python
#!/usr/bin/env python
|
|
|
|
# WS server example
|
|
|
|
import asyncio
|
|
import websockets
|
|
|
|
async def hello(websocket, path):
|
|
await websocket.send(f"> Welcome !")
|
|
|
|
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()
|