title: Private chat using node.js and socket.io
body: <p>Im tryng to create a private chat between a key using a node.js and socket.io, 
  the problem is when i emit a message, that message is not displayed on the room, and i dont know what is the problem...</p>
  
  <p>SERVER</p>
  
  <pre><code> var app = require('express')();
      var express = require('express');
      var http = require('http').Server(app);
      var io = require('socket.io')(http);
      app.use(express.static('./public'));
  
  
      app.get('/', function(req, res){
        res.sendFile(__dirname + '/index.html');
      });
  
  
      io.sockets.on('connection', function(socket){
          console.log("step 0 OK");                  // Works
       socket.on('room', function (room) {
          console.log("step 1 OK");                  // Works
              socket.join(room); 
        });
      });
  
      room = "1234";
  //THIS CODE NOT WORKING
      io.sockets.in(room).emit('message', 'what is going on, party people?'); 
  
  
      http.listen(3000, function(){
        console.log('listening on *:3000');
      });
  </code></pre>
  
  <p>CLIENT</p>
  
  <pre><code> $(document).ready(function() {
  
          var socket = io('http://localhost:3000');
  
          $("#triggerBtn").on("click", function(e) {
              e.preventDefault();
  
              socket.emit('room', '1234');
              return false;
          });
  
  
          socket.on('message', function(data) {
              console.log("Step 2 OK");               //THIS CODE IS NOT EXECUTED
          });
  
  
  
  
      });
  </code></pre>
  
  <p>HTML</p>
  
  <pre><code>&lt;html&gt;
  
  &lt;head&gt;
  
      &lt;title&gt;Bootstrap Case&lt;/title&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
      &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"&gt;
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"&gt;&lt;/script&gt;
      &lt;script src="https://cdn.socket.io/socket.io-1.2.0.js"&gt;&lt;/script&gt;
      &lt;script src="http://code.jquery.com/jquery-1.11.1.js"&gt;&lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  
      &lt;div class="container-fluid"&gt;
          &lt;li&gt;&lt;a href="#"&gt;&lt;button type="button" class="btn btn-default" id="triggerBtn"&gt;Enviar&lt;/button&gt;&lt;/a&gt;&lt;/li&gt;
      &lt;/div&gt;
  
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script src="./bootstrapPage.js"&gt;&lt;/script&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>