websocket for python

https://github.com/aaugustin/websockets

server.py

#!/usr/bin/env python

import asyncio
import websockets

async def send(websocket, path):
while True:
if not websocket.open:
return
name = await websocket.recv()
await websocket.send("{}".format(name))
print("{}".format("{}".format(name)))

start_server = websockets.serve(send, '192.168.2.150', 8765)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()

你可能感兴趣的:(websocket for python)