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()
posted @ 2016-12-15 15:00  火腿骑士  阅读(814)  评论(0编辑  收藏  举报