Joining socket io room on connect

This should be what you need. Feel free to pass in whatever room name you want through the client. Only the server can handle assigning a socket to a room.

Server:

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

Client:

socket.emit('join', roomNum);

There is no .join() method on the client side. Rooms are purely a server-side construct and the client knows nothing about them.

Your first block of code is the desired way to do things. You send the server a message of your design asking it to join the socket to a room and the .join() is executed on the server side.