Dynamic rooms in Socket.io
<p>I'm new in node.js and socket.io. I didn't understand how to work with rooms. I'm creating something like a Private Messages. Each pair of users have their unique room.</p>

<p>From documentation: </p>

<pre><code>io.on('connection', function(socket){
  socket.join('some room');
});
</code></pre>

<p>But I need to create a room from client side. Because it's dynamic. How?</p>

<p>I met some examples <a href="https://gist.github.com/crtr0/2896891" rel="noreferrer">https://gist.github.com/crtr0/2896891</a></p>

<p><strong>server.js</strong></p>

<pre><code>io = socketio.listen(server);

io.sockets.on('connection', function(socket) {
    socket.on('room', function(room) {
        socket.join(room);
    });
});

room = "abc123";
io.sockets.in(room).emit('message', 'what is going on, party people?');
</code></pre>

<p>This line drives me crazy. It seems to me stupid. Because server never know which room to use. Server just can handle multiple rooms.</p>

<pre><code>room = "abc123";
</code></pre>

<p>Please, help or explain.</p>