title: Socket.io connected but not communicating
body: <p>I have a very simple configuration in a node server with socket.io installed (a little bit more complex but essentially like this one):</p>
  
  <pre><code>var main = require('express')();
      server = require('http').createServer(main);
      io = require('socket.io')(server);
  
  io.use(function(socket, next) {
    console.log("middleware!");
    next();
  });
  
  io.on('connection', function (socket) {
    console.log('connected...');
  
    socket.on('pong', function (data) {
      console.log(data.message);
    });
  
    setTimeout(function() {
      console.log("Saying hello");
      socket.emit('ping', { message: 'Hello from server ' + Date.now() });
  
    }, 1000);
  
  });
  
  server.listen(2080, function onCreateServerMain() {
    console.log('Server main is listening on port 2080';
    console.log('************************************************************');
  });
  </code></pre>
  
  <p>In the client:</p>
  
  <pre><code>var socketIoScript,
      loadSocketTimeout,
      trialsToLoadSocketIo = 0,
      APP_CFG = {baseUrl : "http://192.168.1.13:2080"};
  
  function loadSocketIo(socketIoIp) {
    socketIoScript = document.createElement('script');
    socketIoScript.setAttribute('src', socketIoIp);
    socketIoScript.setAttribute('onload', 'onSocketLoaded();');
    document.head.appendChild(socketIoScript);
  }
  
  window.onSocketLoaded = function onSocketLoaded() {
    if (typeof(io.connect) === 'function') {
      var mSocket,
          mIoSocket;
  
      $timeout.cancel(loadSocketTimeout);
      mIoSocket = new io.Manager(APP_CFG.baseUrl);
  
      mIoSocket.connect(function(socket) {
        console.log('Connected!!');
      });
      mIoSocket.on('error', function onSocketError(e) {
        console.log('WebSocket Error ' + error);
      });
  
      mIoSocket.on('ping', function onPingReceived(e) {
        console.log('Server emitted ping: ' + e.data);
        mSocket.emit('pong', 'hi server!');
      });
    }
  }
  
  ~(function onLoadSocketTimeout() {
    var nextTimeout;
  
    if (trialsToLoadSocketIo &lt; 10) {
      nextTimeout = 5000;
    } else if (trialsToLoadSocketIo &gt; 60) {
      nextTimeout = 60000;
    } else {
      nextTimeout = 1000 * trialsToLoadSocketIo;
    }
  
    if (socketIoScript) {
      document.head.removeChild(socketIoScript);
    }
  
    loadSocketIo(APP_CFG.baseUrl + '/socket.io/socket.io.js#' + trialsToLoadSocketIo);
    loadSocketTimeout = $timeout(onLoadSocketTimeout, nextTimeout);
    trialsToLoadSocketIo += 1;
  })();
  </code></pre>
  
  <p>(I'm doing like this because it's mobile app so it may have not connection). I'm testing it with Brackets and Chrome. Server and client are in the same machine. In the app the script is loaded fine and it connects to the server as I can it see in node log <em>(edit: and this is all what I get in the node console)</em>:</p>
  
  <pre><code>Server main is listening on port 2080
  ************************************************************
  middleware!
  connected...
  Saying hello
  </code></pre>
  
  <p><em>Edit: in Chrome console I don't get any message, and any breakpoint stops at <code>on</code> listeners.</em> If I stop node, the console for the <em>Chrome</em> immediately starts logging that it has been disconnected:</p>
  
  <pre><code>GET http://192.168.1.13:2080/socket.io/?EIO=3&amp;transport=polling&amp;t=1413066902601-6 net::ERR_CONNECTION_REFUSED 
  GET http://192.168.1.13:2080/socket.io/?EIO=3&amp;transport=polling&amp;t=1413066906606-7 net::ERR_CONNECTION_REFUSED 
  </code></pre>
  
  <p>But I can't see any incoming message. In the app I don't receive any incoming message. Is there any reason why I could not communicate in this environment even if socket is successfully connected?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>No app is receiving events sent from the other side. Logs from node show this, logs from Chrome are empty.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>In Chrome app I don't receive <code>console.log("Connected!");</code>. But neither I receive <code>ERR_CONNECTION_REFUSED</code> errors: I don't receive anything.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I managed to get <code>console.log("Connected!");</code> in the app by changing Manager options:</p>
  
  <pre><code>  mIoSocket = new io.Manager(APP_CFG.baseUrl, { autoConnect: false });
  </code></pre>
  
  <p>As it was auto connecting and the events were attached after connection was made, "Connected" was never reached. But I'm still not receiving any event in any app.</p>