title: Node.js - tcp server close event handler is not working
body: <p>Why is end event handler(socket) and close event handler(server) is being called at the same time?
  I am expecting close event handler to be called after 30 seconds.</p>
  
  <p>Can someone please help me?</p>
  
  <p>Although after 30 seconds my TCP server is not accepting any new connection(keeps existing connections open) but I was expecting close event handler invocation after 30 sec.
  close event handler of server as well as end event handler of socket is invoked when I forcefully close all existing tcp clients.</p>
  
  <p>TCP connection ended<br>
  TCP connection ended<br>
  server closed but it will keep existing connection</p>
  
  <pre><code>var net = require("net");
  
  function getSocketInfo(socketObject){
                      console.log('bytesRead= ' + socketObject.bytesRead);
                      console.log('bytesWritten= ' + socketObject.bytesWritten);
  }
  
  var tcpServer = net.createServer({allowHalfOpen:false},function(socketObject){
                  socketObject.setEncoding('utf8');
                  getSocketInfo(socketObject);
                  socketObject.on('data',function(data){
                          console.log('data received');
                          console.log(data);
                          console.log(data.length);
                          socketObject.write('Server Reply: ' + data,'utf8',function(){
                          console.log('data successfully written on socket');
                          });
                          getSocketInfo(socketObject);
                          });
  
                  socketObject.on('end',function(){
                          console.log('TCP connection ended');
                          });
                  });
  
  setTimeout(function(){tcpServer.close();},30000);
  
  tcpServer.on('close',function(){ console.log('server closed but it will keep existing connection');});
  
  tcpServer.on('error',function(error){
                  console.log(error.code);
                  });
  
  tcpServer.listen(8000,function(){
                  console.log('TCP server has been bound');
                  });
  </code></pre>