【发布时间】:2017-01-18 07:36:42
【问题描述】:
我看到有一个关于这个主题的问题,但没有列出具体的代码。假设我只想向第一个客户端发出。
例如(在 events.py 中):
clients = []
@socketio.on('joined', namespace='/chat')
def joined(message):
"""Sent by clients when they enter a room.
A status message is broadcast to all people in the room."""
#Add client to client list
clients.append([session.get('name'), request.namespace])
room = session.get('room')
join_room(room)
emit('status', {'msg': session.get('name') + ' has entered the room.'}, room=room)
#I want to do something like this, emit message to the first client
clients[0].emit('status', {'msg': session.get('name') + ' has entered the room.'}, room=room)
这是如何正确完成的?
谢谢
【问题讨论】:
标签: python flask flask-socketio