代码拉取完成,页面将自动刷新
from flask import Flask
from flask_sockets import Sockets
import json
from gevent import pywsgi
from geventwebsocket.handler import WebSocketHandler
app = Flask(__name__)
Sockets = Sockets(app)
sok = {}
@Sockets.route('/test')
def socketResponse(ws):
# send = {}
# send['msg'] = "hello"
# send['faname'] = "钟科杰"
# send['shouname'] = "陈霖"
# send['toid'] = "1111"
# ws.send(json.dumps(send))
while not ws.closed:
re = ws.receive()
if re is not None:
print("收到的信息为:" + re)
id = re.id
if id in sok.keys():
print("此id已存在")
else:
sok.setdefault('id',ws)
else:
print("no receive")
@app.route('/')
def hello():
return 'Hello World! server start!'
if __name__ == "__main__":
server = pywsgi.WSGIServer(('0.0.0.0', 5000), app, handler_class=WebSocketHandler)
print('server start')
server.serve_forever()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。