title: socket.io data from server to client
body: <p>server.js</p>
  
  <pre><code>var express = require('express');
  var app = express();
  var server = require('http').createServer(app);
  var io = require('socket.io')(server);
  
  app.use(express.static(__dirname + '/public'));
  
  io.on('connection', function(client) {
      console.log('Client connected...');
  
  client.on('join', function(data) {
      console.log(data);
      io.emit('messages', 'Hello');
  
  });
  
  });
  </code></pre>
  
  <p>index.html</p>
  
  <pre><code>&lt;script&gt;
      var socket = io.connect('http://localhost:7777');
      socket.on('connect', function(data) {
        socket.emit('join', 'Hello World from client');
  
      });
      socket.on('messages', function(data) {
        alert(data);
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>I tried to implement very basic of Socket.io.</p>
  
  <p>However, data sending from client to server is available but from server to client doesn't work. </p>
  
  <p>In the command running server.js, 'Hello World from client' is printed. However, alert window doesn't work in the web browser.(I've also tried to console.log).</p>
  
  <p>How to solve this?</p>
  
  <p><strong>Editted</strong></p>
  
  <p>I've put server.js codes in the app.get('/', function(req, res)){ ... }
  Then, it doesn't work. Why it doesn't work in app.get?</p>