python snippets -1#

#!/usr/bin/env python
import asyncio as io
import websockets as ws

async def hello(websocket, path):
        name = await websocket.recv()
        greeting = f"Hello {name}!"
        await websocket.send(greeting)

server = ws.serve(hello, 'localhost', 1337)
io.get_event_loop().run_until_complete(server)
io.get_event_loop().run_forever()