Socket模式下的私人信息

我列出用户从用户数组与套接字io.İfı点击用户名模式将打开并发送消息到ı点击用户。

这里服务器端:

socket.on('privatemessage', function(data){ if (data == "" || data == undefined) { socket.emit('alert',{ value:"write a message" }); } else { if (socket.nick in users) { socket.in(socket.nick).emit('sendmessage', socket.name, data); } else { console.log('message not send'); } } }); socket.on('username', function(nick){ socket.nick=nick; socket.emit('updatemodal', nick); }); 

socket.nick是被点击的用户。

和客户端:

 socket.on('sendmessage', function(name, data){ output.innerHTML += '<p><strong>' + name + ' :</strong>' + data + '</p>'; $(document).ready(function(){ $("#myModal").modal(); }); }); 

模态;

 <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> <h4 class="modal-title" id="myModalLabel"></h4> </div> <div class="modal-body"> <div id="modalpencere"> <div id="output"></div> <div id="modalfeedback"></div> </div> <br> <div class="input-group"> <input type="text" style="resize: vertical;" id="modalmesaj" class="form-control" placeholder="Mesaj"> <span class="input-group-btn"> <button type="button" id="modalgonder" class="btn btn-primary">Gönder<span class="glyphicon glyphicon-menu-right" aria-hidden="true"></span></button> </span> </div> </div> <div class="modal-footer"> <button type="button" id="modalcikis" class="close" data-dismiss="modal">Çıkış</button> </div> </div> </div> </div> 

我更新post.Pls帮助我。

Solutions Collecting From Web of "Socket模式下的私人信息"