title: Emit socket.io message on http get request (in Express.js)
body: <p>In my socket.io / express app I'd like to be able to make a GET request to localhost:3000/send and have that emit a message to all open connections however, this code doesn't seem to be working:</p>
  
  <pre><code>var LISTENING_PORT = 1234;
  
  var app = require('express')();
  var http = require('http').Server(app);
  var io = require('socket.io')(http);
  
  //Example users
  app.get('/messages', function(req, res){
    res.sendFile(__dirname + '/messages.html');
  });
  
  //Basket Reservation Namespace
  var basket_reservation = io
    .on('connection', function(socket){
      socket.on('message', function(message){
        console.log('Received connection from user: ' + message);
        socket.emit('message', 'Connection started.');
      });
  
      app.get('/send', function(req, res){
        console.log('sending message to all');
        socket.emit('message', 'Message from GET /send');
        res.send('Message sent.');
      });
    });
  
  http.listen(LISTENING_PORT, function(){
    console.log('listening on *:' + LISTENING_PORT);
  });
  </code></pre>
  
  <p>Specifically the line socket.emit('message', 'Message from GET /send'); does not work. The lines above and below it do get called.</p>
  
  <p>Here is the client:</p>
  
  <pre><code>&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;script type="text/javascript"&gt;
    var socket = io('http://localhost:1234/');
    socket.emit('message', 'hello');
    socket.on('message', function(msg){
      $('#messages').append($('&lt;li&gt;').text(msg));
    });
  &lt;/script&gt;
  
  &lt;h1&gt;User #1&lt;/h1&gt;
  
  
  &lt;ul id="messages"&gt;&lt;/ul&gt;
  </code></pre>