在我的app
中,我需要client
加入一个room
,以便它可以receive
从我的server
.
服务器代码
@socketio.on('join', namespace='/test')
def join(message):
join_room(message['room'])
room = message['room']
emit('my response', {'data': 'Entered the room ' + message['room']}, room=room)
@app.route('/scan/user/<int:user_id>/venue/<int:venue_id>', methods = ['POST'])
@auth.login_required
def scan_tablet_user_func(user_id, venue_id):
room = 'venue_' + str(venue_id)
socketio.emit('my response', {'data': json.dumps(my_info, ensure_ascii=False)}, room=room)
客户代码
$('form#join').submit(function(event) {
socket.emit('join', {room: $('#join_room').val()});
return false;
});
webpage
加载后,我进入了"venue_1"
有webpage form
资格的"join"
.
侧面的也设置variable
room
为。server
"venue_1"
问题是,当我调用 时API
/scan/user/...
,我的client
. 然而,
emit('my response', {'data': 'Entered the room ' + message['room']}, room=room)
确实显示正确。