代码拉取完成,页面将自动刷新
同步操作将从 陈不不/cyrpc框架 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
from flask import Flask,request
import threading
import asyncio
import websockets
import json
import time
from websocket import create_connection
app = Flask(__name__)
getDataInfoTo = {}
dataonDthis = {}
@app.route('/cbb', methods=["GET","POST"])
def getRpcDate():
if request.method == "GET":
print(request.args)
typeOfDate = request.args.get('type')
data = request.args.get('data')
webId = request.args.get('webId')
reqData = typeOfDate+data
getDataInfoTo[webId] = reqData
ws = create_connection("ws://127.0.0.1:5679/getInfo")
ws.send("ko---c~c")
ws.recv()
ws.close()
while 1:
if webId in dataonDthis:
dateInfo = dataonDthis[webId]
dataonDthis.pop(webId)
break
return dateInfo
elif request.method == "POST":
typeOfDate = request.form.get('type')
data = request.form.get('data')
webId = request.form.get('webId')
reqData = typeOfDate + data
getDataInfoTo[webId] = reqData
ws = create_connection("ws://127.0.0.1:5679/getInfo")
ws.send("ko---c~c")
ws.recv()
ws.close()
while 1:
if webId in dataonDthis:
dateInfo = dataonDthis[webId]
dataonDthis.pop(webId)
break
return dateInfo
return 'web后端请求出现错误!!!'
@app.route('/getID')
def getId():
return json.dumps(list(webScoketDist))
async def get_sesson(ws, path):
# while 1:
async for message in ws:
print(message)
Id = message.split('---')[0]
data = '---'.join(message.split('---')[1:])
print(path)
print(Id)
print(data)
print('___________________________')
if path == '/cbb':
if Id not in webScoketDist:
webScoketDist[Id] = ws
if data != 'c~c':
dataonDthis[Id] = data
else:
print('zh异步')
await ws.send(getDataInfoTo[Id])
adInfo = await ws.recv()
dataonDthis[Id] = adInfo
getDataInfoTo.pop(Id)
elif path == '/getInfo':
print(getDataInfoTo)
print(webScoketDist)
for i in list(getDataInfoTo):
print(webScoketDist)
print(i)
if i in webScoketDist:
await webScoketDist[i].send('c~c')
await ws.send('1')
def cbb():
c_loop = asyncio.new_event_loop()
asyncio.set_event_loop(c_loop)
start_server = websockets.serve(get_sesson, '0.0.0.0', 5679)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
if __name__ == '__main__':
webScoketDist = {}
yhh = threading.Thread(target=cbb)
yhh.start()
time.sleep(2)
app.run(host='0.0.0.0', port=9420)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。