您必须与创建一个房间
conversation_id并让用户订阅该房间,以便您可以向该房间发送私人消息,
客户
var socket = io.connect('http://ip:port');socket.emit('subscribe', conversation_id);socket.emit('send message', { room: conversation_id, message: "Some message"});socket.on('conversation private post', function(data) { //display data.message});服务器
socket.on('subscribe', function(room) { console.log('joining room', room); socket.join(room);});socket.on('send message', function(data) { console.log('sending room post', data.room); socket.broadcast.to(data.room).emit('conversation private post', { message: data.message });});以下是创建会议室,订阅会议室并将消息发送到会议室的文档和示例:
- Socket.io房间



