create room socket io
// client side code
var socket = io.connect();
socket.emit('create', 'room1');
// server side code
io.sockets.on('connection', function(socket) {
socket.on('create', function(room) {
socket.join(room);
});
});
create room socket io
// client side code
var socket = io.connect();
socket.emit('create', 'room1');
// server side code
io.sockets.on('connection', function(socket) {
socket.on('create', function(room) {
socket.join(room);
});
});
rooms in socket io
io.on('connection', socket => {
socket.join('some room');
});
//And then simply use to or in (they are the same) when broadcasting or emitting:
io.to('some room').emit('some event');
//You can emit to several rooms at the same time:
io.to('room1').to('room2').to('room3').emit('some event');
//In that case, an union is performed: every socket that is at least in one of the rooms will get the event once (even if the socket is in two or more rooms).
//You can also broadcast to a room from a given socket:
io.on('connection', function(socket){
socket.to('some room').emit('some event');
});
create room socket io
io.sockets.in(room).emit('event', data);
create room socket io
socket.on('create', function (room) {
socket.join(room);
});
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us