title: Cannot emit socket message from client
body: <p>So, I'm setting up an express app, with all the usual goodies like passport, mongoose, connect-flash etc, and I'm using socket.io to listen for and emit messages.</p>
  <p>Currently, I'm just emitting messages to everyone (will be setting up rooms later on) and everything (but this) is working great. When an end user visits any page, all currently connected users receive a message &quot;Hi everyone!&quot;, and the user who just connected obviously sends them self the message too. All as expected so far...</p>
  <p><strong>The issue:</strong>
  I have a page that has a button on it...</p>
  <p><code>&lt;button id=&quot;register&quot; type=&quot;button&quot; class=&quot;btn btn-warning&quot;&gt;Register&lt;/button&gt;</code></p>
  <p>When clicked, this should emit a message saying 'I want to register!' (currently to everyone but that doesn't matter yet). In response, the server should listen for this and respond by emitting a message back saying 'Hmmm, will think about it!'.</p>
  <p>'registering' is never heard at the server, and so cannot emit the reply of 'registration-response'.</p>
  <h1>Can anyone see what I'm doing wrong?</h1>
  <p>I've seen this <a href="https://stackoverflow.com/questions/27369553/socketio-cant-send-emit-data-from-client">SocketIO, can&#39;t send emit data from client</a> and a couple others that are similar but I am already doing what they have suggested :/</p>
  <p><strong>NB</strong>: The app is running on <code>http://localhost:3000/</code> and the io using <code>http://localhost:8678/events</code>. If you need any further info just let me know</p>
  <p><strong>Client-side JS/jQuery (app.js)</strong></p>
  <pre><code>var app = app || {};
  
  app = (function($){
  
      $(function () {
      
          /////////////////////////////////////////////////////
          // Connect to io and setup listeners
          /////////////////////////////////////////////////////
  
          var socket = io.connect('http://localhost:8678/events');
          socket.on('connected', function (data) {
              console.log(data); // Always see this in the console
          });
  
          socket.on('registration-response', function (data) {
              console.log(data); // NOT seen in console
          });
  
          /////////////////////////////////////////////////////
          // Setup click events
          /////////////////////////////////////////////////////
  
          $('#register').on('click', function(){
              console.log('click'); // Always see this, so no binding issue
              socket.emit('registering', 'I want to register!');
          });
      });
  
  })(jQuery);
  </code></pre>
  <p><strong>Server-side JS</strong></p>
  <pre><code>var app = require('express');
  var http = require('http');
  var server = http.createServer(app);
  var io = require('socket.io').listen(server);  //pass a http.Server instance
  server.listen(8678);  //listen on port 8678
  
  ////////////////////////////////////////
  // Register event listeners     
  ////////////////////////////////////////
  
  var events = io.of('/events');
  
  events.on('connection', function(socket){ // This is heard and callback fires
    events.emit('connected', 'Hi everyone!'); // This gets sent fine
  });
  
  events.on('registering', function(data){
    events.emit('registration-response', 'Hmmm, will think about it!');
  });
  </code></pre>