1
私はこのトピックについての質問があるが、特定のコードの概要は説明されていません。最初のクライアントだけに送信したいとします。 (events.pyで)例えばフラスコsocketio特定のユーザーに送信
:
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 = []
@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(request.sid)
room = session.get('room')
join_room(room)
# emit to the first client that joined the room
emit('status', {'msg': session.get('name') + ' has entered the room.'}, room=clients[0])
あなたが見ることができるように、各クライアントが持っている:私は最初のクライアントへの放出の背後にあるロジックを理解してわからないんだけど、とにかく、これはそれを行う方法である
おかげ
お返事ありがとうございます。ええ、私は実際にこれをやっていないでしょう。私はあなたが特定のクライアントに放出する例を作成しようとしていました。ミゲル再びありがとう、非常に感謝! – shell