我正在尝试SocketIO而且我被卡住了.我找不到任何适当的文件.
以下是我想要做的示例代码:
io.sockets.in('group1').join('group2');
io.sockets.in('group3').on('message', function(){});
Run Code Online (Sandbox Code Playgroud)
这两个特定的行动有没有解决方法?
小智 8
你需要做的是将套接字加入()到一个组:
var io = require('socket.io').listen(80);
io.sockets.on('connection', function (socket) {
socket.join('justin bieber fans'); // put socket in a channel
socket.broadcast.to('justin bieber fans').emit('new fan'); // broadcast a message to a channel
io.sockets.in('rammstein fans').emit('new non-fan'); // to another channel
});
Run Code Online (Sandbox Code Playgroud)
您需要为连接到您的每个套接字执行此操作.
这是来自https://github.com/LearnBoost/socket.io(搜索房间)的文档.
| 归档时间: |
|
| 查看次数: |
1916 次 |
| 最近记录: |