title: Socket.io-client simple client/server test wont connect - Node.js
body: <p>I am trying to get some simple communication to work in Node.js using socket.io and socket.io-client.</p>
  
  <p>I have two scripts, server.js and client.js.</p>
  
  <p>The server.js script can bind to a webfacing port and act like a normal server/socket.io host, which all works when used with the browser client, </p>
  
  <p>but the client.js (running in another node script) doesn't work, it just waits not outputting anything. I expect my socket.io-client in client.js to connect to the socket.io instance in server.js and for both to display a message in their console to say they're connected.</p>
  
  <p>server.js code:</p>
  
  <pre><code>var app = require('express')();
  var http = require('http').Server(app);
  var io = require('socket.io')(http);
  
  app.get('/', function(req, res){
      console.log("\nNew server request: "+req.url+"\n");
  
      // sends a html file with a script that connects
      // to socket.io running in server.js
      res.sendFile(__dirname+'/webroot/index.html');
  });
  
  // listens for connections
  io.on('connect', function(socket){
    console.log('a client connected');
  });
  
  // start listening on server
  http.listen(9000, function(){
    console.log('listening: 9000');
  });
  </code></pre>
  
  <p>client.js code:</p>
  
  <pre><code>var io = require('socket.io-client');
  
  // connect to server.js socket
  var socket = io('http://hostsite.com', {
      port: 9000
  });
  
  socket.on('connect', function(){
      console.log("connected\n");
  });
  </code></pre>
  
  <p>installed with npm</p>
  
  <pre><code>npm install socket.io // version: 1.0.6
  npm install socket.io-client // version: 1.0.6
  npm install express // version: 4.8.5
  </code></pre>
  
  <p>Ideally I don't want to be using express or an http server, just a socket communication between two Node.js scripts, one on a server machine, one on a client machine.</p>
  
  <p>Thanks for any help :)</p>