title: Nodejs Net TCP client data event triggered without any write action in server side
body: <p>I was using net module to build a simple server/client example.  The client side just send a simple message after connection is built, and server side didn't do anything but just print some log, but after that I found the data event in client side got triggered, and the data received is the data it send to the server (but server didn't write anything to client).</p>
  
  <p>Client.js:</p>
  
  <pre><code>var net = require('net');
  
    var port = 3540;
    var hostName = "127.0.0.1";
  
    var client = new net.Socket();
    client.connect(port, hostName, function() {
       console.log("Connected to the remote host: " + hostName + ":" + port);
       client.write("hello,world");
       client.end();
    });
    var bytesReceived = 0;
    client.on('data', function(data) {
      bytesReceived += data.length;
      console.log('Received bytes: ' + data.length + ', total bytes received: ' + bytesReceived);
      console.log(data.toString())
      })
  
    client.on('error', function(error) {
      console.log(error);
      client.destroy();
    });
  
    client.on('close', function() {
      console.log('Closed connection');
    })
  </code></pre>
  
  <p>server.js:</p>
  
  <pre><code>var net = require('net');
      port = 3540;
  
  var log = function(who, what) {
    return function() {
      var args = Array.prototype.slice.call(arguments);
      console.log('[%s on %s]', who, what, args);
    };
  };
  var count = 0
  var echo = function (socket) {
    socket.on('end', function() {
      console.log('recevied a FIN packet');
      socket.end();
    });
    socket.on('data', function(data) {
      console.log(count + ': received bytes: ' + data.length);
      count++;
    });
    socket.on('error', function(error) {
      console.log(error);
      socket.destroy();
    });
    socket.on('close', function() {
      console.log('connection has been closed!');
    });
    socket.pipe(socket);
  }
  
  
  var server = net.createServer(echo);
  server.listen(port); // port or unix socket, cannot listen on both with one server
  
  server.on('listening', function() {
    var ad = server.address();
    if (typeof ad === 'string') {
      console.log('[server on listening] %s', ad);
    } else {
      console.log('[server on listening] %s:%s using %s', ad.address, ad.port, ad.family);
    }
  });
  
  server.on('connection', function(socket) {
    server.getConnections(function(err, count) {
      console.log('%d open connections!', count);
    });
  });
  
  server.on('close', function() { console.log('[server on close]'); });
  server.on('err', function(err) {
    console.log(err);
    server.close(function() { console.log("shutting down the server!"); });
  });
  </code></pre>
  
  <p>After that the client print out:</p>
  
  <pre><code>Connected to the remote host: 127.0.0.1:3540
  Received bytes: 11, total bytes received: 11
  hello,world
  Closed connection
  </code></pre>