试试这个:
socket.on('pmessage', function (data) { // we tell the client to execute 'updatechat' with 2 parameters io.sockets.emit("pvt",socket.username,data+socket.username); io.sockets.socket(socket.id).emit("pvt",socket.username,data+socket.username); });socket.id由socket.io保存,并且包含客户端的唯一ID。您可以使用以下命令进行检查:
console.log(socket.id);



