title: EC2 with socket.io
body: <p>I have set up an aws micro instance for my node application. I use <code>socket.io</code> as well. I am getting the following error: </p>
  
  <pre><code>GET http://localhost:3000/socket.io/1/?t=1393065240268 net::ERR_CONNECTION_REFUSED
  </code></pre>
  
  <p>in the console at the moment when the socket connection should be created. Apart from this the node app works. I suspect that the <code>GET</code> should not be towards <code>localhost</code> but towards the address of the server.</p>
  
  <p>Note that on the server side node logs that it served <code>socket.io</code>: </p>
  
  <pre><code>debug - served static content /socket.io.js
  </code></pre>
  
  <p>Here is a picture of the Security Group of my server:</p>
  
  <p><img src="https://i.stack.imgur.com/xI4dR.png" alt="Security Group">.</p>
  
  <p>Socket.io setup:</p>
  
  <pre><code>env = process.env.NODE_ENV || 'development',
  packageJson = require('../package.json'),
  http = require('http'),
  express = require('express'),
  RedisStore = require('connect-redis')(express),
  SessionSockets = require('session.socket.io'),
  path = require('path'),
  settings = require('./settings'),
  expose = require('express-expose')
  //Configure server for io and session.socket.io
  tmpApp = express(),
  tmpServer = http.createServer(tmpApp),
  io = require('socket.io').listen(tmpServer),
  appCookieParser = express.cookieParser(settings.cookie.secret),
  appRedisStore = new RedisStore(),
  sessionIO = new SessionSockets(io, appRedisStore, appCookieParser)
  
  global.App = {
      app: tmpApp,
      server: tmpServer,
      port: process.env.PORT || 3000,
      sessionIO: sessionIO,
      io: io,
      start: function() {
          var setUp = this.util('setUp'),
              socketHandler = require('./socketHandler'),
              self = this
  
              setUp.initialize(function(err, waitingGames) {
                  if (err) {
                      console.log('error at initializing the application')
                      process.exit(0)
                  }
                  if (!self.started) {
                      self.started = true
                      self.server.listen(self.port)
  
                      socketHandler()
  
                      console.log("Running App Version " + App.version + " on port " + App.port + " in " + App.env + " mode")
                  }
              })
  
      },
   ...
   }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>When I changed my port to <code>80</code> I get a different error:</p>
  
  <pre><code> XMLHttpRequest cannot load http://localhost/socket.io/1/?t=1393067003774. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://ec2-54-214-136-70.us-west-2.compute.amazonaws.com' is therefore not allowed access. 
  </code></pre>