我正在尝试创建一个简单的WebSocket连接。当我执行下一个代码时,我的服务器接收到字符串“hey!”客户收到字符串“哟!”,此时一切正常,但当我在其他视图中单击时,服务器冻结。在
代码:
客户端:
html格式:
<ul>
<li><a class="active" href="#home">Home</a></li>
<li><a href="editor-page2">News</a></li>
</ul>
JavaScript代码:
^{pr2}$服务器端:
from flask import Flask, render_template
from flask.ext.socketio import SocketIO, emit
app = Flask('flaskwp1')
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)
@app.route('/editor-page1')
def webprint():
return render_template('editor-page1.html')
@app.route('/editor-page2')
def webprint2():
return render_template('editor-page2.html')
@socketio.on('my event', namespace='/test')
def handle_my_custom_event(json):
print('received json: ' + str(json))
emit('my response', {'data': 'yo!'})
目前没有回答
相关问题 更多 >
编程相关推荐