Broadcast

Other topics

Broadcasting to all users

It is possible to send a message or data to all avaible connections. This can be achieved by first initializing the server and then using the socket.io object to find all sockets and then emit as you normally would emit to a single socket

var io = require('socket.io')(80) // 80 is the HTTP port
io.on('connection', function (socket) {
      //Callback when a socket connects
    );
io.sockets.emit('callbackFunction',data); 

Broadcast to all other sockets

It is possible to emit a message or data to all users except the one making the request:

var io = require('socket.io')(80);
io.on('connection', function (socket) {
  socket.broadcast.emit('user connected');
});

Contributors

Topic Id: 6295

Example Ids: 21751,21752

This site is not affiliated with any of the contributors.