title: File/Data transfer between two node.js servers
body: <p>I am trying to set up a small system having one server (aka sensor) transfer data files to another server (aka server) (both running node.js apps) when it sees that the other is available.</p>
  
  <p>The server should ideally be listening for a connection from the sensor, when connection is made, the sensor will transfer all available data files to the server, then close the connection.</p>
  
  <p>I have been playing around with a library called delivery.js (<a href="https://github.com/liamks/Delivery.js" rel="nofollow">https://github.com/liamks/Delivery.js</a>), it looks promising when reading through the documentation, however, being a novice js programmer, I am struggling to understand why my attempt at the example is not working.</p>
  
  <p>I am using the following code on the sensor:</p>
  
  <pre><code>var io  = require('socket.io'),
      dl  = require('delivery'),
      fs  = require('fs');
  
  var socket = io.connect('http://192.168.0.14:5001');
  
  socket.on('connect', function() {
    log( "Sockets connected" );
  
    delivery = dl.listen( socket );
    delivery.connect();
  
    delivery.on('delivery.connect',function(delivery){
      delivery.send({
        name: 'sample-image.jpg',
        path : './sample-image.jpg'
      });
  
      delivery.on('send.success',function(file){
        console.log('File sent successfully!');
      });
    });
  
  });
  </code></pre>
  
  <p>And the server running the example code:</p>
  
  <pre><code>var io  = require('socket.io').listen(5001),
      dl  = require('delivery');
  
  io.sockets.on('connection', function(socket){
    var delivery = dl.listen(socket);
    delivery.on('delivery.connect',function(delivery){
  
      delivery.send({
        name: 'sample-image.jpg',
        path : './sample-image.jpg'
      });
  
      delivery.on('send.success',function(file){
        console.log('File successfully sent to client!');
      });
  
    });
  });
  </code></pre>
  
  <p>The server code runs fine and creates the socket listening for communication. However, the sensor code throws error:</p>
  
  <pre><code>/Users/Oliver/Desktop/socket/delivery/test-delivery-client.js:5
  var socket = io.connect('http://192.168.0.14:5001');
                  ^
  TypeError: Object #&lt;Object&gt; has no method 'connect'
      at Object.&lt;anonymous&gt; (/Users/Oliver/Desktop/socket/delivery/test-delivery-client.js:5:17)
      at Module._compile (module.js:449:26)
      at Object.Module._extensions..js (module.js:467:10)
      at Module.load (module.js:349:32)
      at Function.Module._load (module.js:305:12)
      at Function.Module.runMain (module.js:490:10)
      at startup (node.js:123:16)
      at node.js:1029:3
  </code></pre>
  
  <p>If anyone could explain where i am going wrong and indicate how to get my needs met, that would be great. Thanks in advance.</p>