title: Socket.io Error: listen EADDRINUSE
body: <p>I have a small problem. I want to run a webserver and allow it to communicate with server using socket.io but i get:</p>
  
  <p><img src="https://i.stack.imgur.com/CvAVU.png" alt="enter image description here"></p>
  
  <p><strong>POST UPDATE</strong></p>
  
  <p><strong>Chat Class:</strong></p>
  
  <pre><code>/**
   * Chat Class
   */
  
  // module dependencies
  var io = require('socket.io'); 
  // self instance
  var self = this;
  
  /**
   * Constructor 
   *
   * @param {server}
   * @param {userlist}
   */
  var Chat = function(server) {
      this.server = server;
  };
  
  // Init
  Chat.prototype.init = function() {
      // socket instance
      self.sock = io.listen(self.server);
  };
  
  module.exports = Chat;
  </code></pre>
  
  <p><strong>Main:</strong></p>
  
  <pre><code>// socket http server
  var server = http.createServer(app).listen(app.get('port'), function(){
      // chat server init
      console.log('Listening on port ' + app.get('port'));
  });
  
  // chat
  var chat = new Chat(server, userlist);
  chat.init();
  </code></pre>
  
  <p><strong>But if i try without chat class encapsulation, it works:</strong></p>
  
  <pre><code>// socket http server
  var server = http.createServer(app).listen(app.get('port'), function(){
      // chat server init
      console.log('Listening on port ' + app.get('port'));
  });
  
  var io = require('socket.io'); 
  
  io.listen(self.server);
  </code></pre>
  
  <p>So, what i'm doing bad ? </p>
  
  <p>Thanks in advance.</p>