how rooms work. And another chat example.

I continue to learn nodejs and Today I will explain how do rooms work. Since for me it’s was quite difficult to understand in details what is it and how it work.

And yes still I’m consider myself not a pro in nodejs and So this articles addressed to developers who is also just started their node way.

Ok Go. If we look at rooms docs  we will find the info how to use rooms but there’s no way to understand HOW it works.

In fact it’s quite straightforward. But let’s see it in details. And we need start from io object. What is it?

var io = require('')(http);


As you see io keeps info about all connected sockets. This means that you can access socket object if you know it’s ID.

var socket = io.sockets.connected[socketId];

So every socket has it’s own ID. It is generated for each new socket. Now let’s look at socket instance connected to one room.


As you see default socket ID automatically added to rooms.  Therefore when we need to send message to sockets in certain room…'message', {message: "details"});

(as I can assume) Socket.IO just go through the socket.rooms of the connected sockets and selects sockets that has specified room id. Easy? I think yes. But I must admit I spent some time to get this point.

I hope this could be useful. Also looking ahead I published another nodejs chat example using you can check it out. This could be a good start point to create your own chat with blackjack.



4 thoughts on “ how rooms work. And another chat example.

  1. Pingback: how rooms work. – Abdullah Adeeb

Leave a Reply

Your email address will not be published. Required fields are marked *