我看到有一个关于这个主题的问题,但具体的代码没有概述。比如说我只想向第一个客户端发出信号。
例如(在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)
如何正确地完成这个任务?
谢谢
clients[0]
和session.get('room')
是相同的吗?我们不应该执行join_room(request.sid)
吗? - Phani Rithvijsid
作为房间的名称。 - Miguel Grinberg