Last active
December 29, 2015 07:29
-
-
Save kejyun/7636628 to your computer and use it in GitHub Desktop.
socket io 傳送訊息方式整理
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
socket.on('send', function(msg) { | |
// 廣播資訊給在socket.room的人,除了發送者自己 | |
socket.broadcast.to(socket.room).emit('updatechat', msg); | |
// 傳送更新資訊給自己 | |
socket.emit('updatechat', msg); | |
socket.to(socket.room).emit('updatechat', msg); | |
// 傳送資訊給所有socket | |
io.sockets.emit('updatechat', msg); | |
// 傳送資訊給在socket.room的連線 | |
io.sockets.in(socket.room).emit('updatechat', msg); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment