程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

python websocket

編輯:Python
#-*-coding:utf8;-*-
#qpy:console
import asyncio
import websockets as ws
import json
from websockets import ConnectionClosed
async def hello():
uri = "ws://127.0.0.1:6700"
while True:
try:
async with ws.connect(uri) as websocket:
await websocket.send(json.dumps({
"echo":"11111","action":"send_group_msg","params":{
"group_id":588093810,"message":"Hello你好"}}))
while True:
try:
data = await websocket.recv()
print(json.loads(data))
#await websocket.send(json.dumps({"echo":"11111","action":"send_group_msg","params":{"group_id":5880938010,"message":"Hello"}}))
if "12580" in data:
await websocket.send(json.dumps({
"echo":"11111","action":"send_group_msg","params":{
"group_id":5880938010,"message":"Hello你好"}}))
print(""+data)
except ConnectionClosed as e:
print(e.code)
break
except:
pass
if __name__=="__main__":
asyncio.get_event_loop().run_until_complete(hello())

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved