Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodejs and socket.io chat rooms

Is it possible to create chat rooms dynamically with socket.io ? All the examples I've seen so far had every room declared implicitly. I am looking to achieve something like http://tlk.io/ where you simply create a chat room by accessing a random url, and then allow users in based on certain criteria.

like image 581
andrei Avatar asked Dec 28 '11 10:12

andrei


People also ask

Is Socket.IO good for chat?

So as we all know Socket.io is the best solution for instant messaging app and its reliability.

Should I use WebSockets for chat?

WebSockets are a great fit for applications like chats or simple games. Chat sessions are usually long-lived, with the client receiving messages from other participants over a long period of time. Chat sessions are also bidirectional – clients want to send chat messages, and see chat messages from others.


1 Answers

Yes. socket.io has a rooms feature.

From the readme:

var io = require('socket.io').listen(80);

io.sockets.on('connection', function (socket) {
  socket.join('justin bieber fans');
  socket.broadcast.to('justin bieber fans').emit('new fan');
  io.sockets.in('rammstein fans').emit('new non-fan');
});
like image 59
fent Avatar answered Oct 05 '22 19:10

fent