目前我遇到的问题是我得到了所有用户的回复。 我想在单个聊天模块中通知选定用户。
如下所示我想向此" userid"发送通知只有
客户端文件代码位于
之下var forwardString =
{
"userid": actual_receiverID,
"id": msgId
};
socket.emit('insertReceiverIdInMessageForwardReq',forwardString);
socket.on('insertReceiverIdInMessageForwardRes', function (messages) {
var updatedMsg = messages.Messages;
});
------------------服务器端代码------------------
io.on('connection', function (socket) {
socket.on('insertReceiverIdInMessageForwardReq', function (status) {
io.emit('insertReceiverIdInMessageForwardRes', res);
});
});
答案 0 :(得分:0)
// sending to individual socketid (private message)
socket.to(<socketid>).emit('hey', 'I just met you');
// or you can do this as well
io.sockets.connected[<socketid>].emit('hey', 'I just met you');
请参阅文档以获取更多详细信息:https://socket.io/docs/emit-cheatsheet/