相关疑难解决方法(0)

如何使用socket.io向特定客户端发送消息

我从socket.io + node.js开始,我知道如何在本地发送消息和广播socket.broadcast.emit()功能: - 所有连接的客户端都收到相同的消息.

现在,我想知道如何向特定客户端发送私人消息,我的意思是一个套接字用于2人之间的私人聊天(客户端到客户端流).谢谢.

javascript ajax jquery node.js socket.io

85
推荐指数
6
解决办法
9万
查看次数

烧瓶socketio向特定用户发出

我看到有关于此主题的问题,但具体代码未概述.假设我只想向第一个客户端发射.

例如(在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)
Run Code Online (Sandbox Code Playgroud)

这怎么做得好?

谢谢

python flask flask-socketio

6
推荐指数
1
解决办法
5580
查看次数

标签 统计

ajax ×1

flask ×1

flask-socketio ×1

javascript ×1

jquery ×1

node.js ×1

python ×1

socket.io ×1