title: How to host a socket.io server and a http server together?
body: <p>I have a <code>Socket.io</code> server and a basic HTTP server that I coded together, but the problem is that the HTTP-server tries to serve requests that <code>socket.io</code> should serve.</p>
  
  <p>Code:</p>
  
  <pre><code>//Dependences
  var sio = require('socket.io');
  var http = require("http");
  var NewRequestHandler = require('./NewRequestHandler').Handler;
  var DisconnectHandler = require('./DisconnectHandler').Handler;
  var AuthorisationRequestHandler = require('./AuthorisationRequestHandler').Handler;
  //The backlog of resources
  var ResourceBackLog;
  
  var ResourceRequestHandler = require("./ResourceRequestHandler").Handler;
  //Reports the IP adress and Port that it will run on.
  console.log('IP address: ' +  process.env.IP);
  console.log('Port: ' + process.env.PORT);
  //Creates and configures a new http.server instance.
  var Server = new http.Server();
  
  //Starts both the http and socket.io server.
  var io = sio.listen(Server.listen(process.env.PORT, process.env.IP, ResourceBackLog, function(error) {
      if (error) {
          console.log("Error: " + error);
      } else if (!error) {
          console.log("Server started sucsessfully.");
          Server.on('request', ResourceRequestHandler);
          console.log("Server now ready for requests.");
      }
  }));
  
  //Handles the connect and authorisation bit
  io.sockets.on('connection', function(socket) {
      console.log('New Connection');
      socket.on('auth', function(Keys) {
      console.log('Autorisation Request Recived');
          AuthorisationRequestHandler(socket, Keys, function() {
              socket.on('NewRequest',  function(Request) {
                  NewRequestHandler(socket, Request);
              });
              socket.on('diconnect', function() {
                  DisconnectHandler(socket);
              });
          });
  
      });
  });
  </code></pre>
  
  <p>The ResourceRequestHandler is the file that serves resources by checking the URL then opening the file at that location,
  but it also serves /socket.io requests.</p>