title: How to properly close a Node.js TCP server?
body: <p>I couldn't find a clear answer on Google or SO.</p>
  
  <p>I know a <code>net.Server</code> instance has a <code>close</code> method that doesn't allow any more clients in. But it doesn't disconnect clients already connected. How can I achieve that?</p>
  
  <p>I know how this can be done with Http, I guess I'm asking if it's the same with Tcp or if it's different.</p>
  
  <p>With Http, I'd do something like this:</p>
  
  <pre><code>var http = require("http");
  
  var clients = [];
  
  var server = http.createServer(function(request, response) {
      response.writeHead(200, {"Content-Type": "text/plain"});
      response.end("You sent a request.");
  });
  
  server.on("connection", function(socket) {
      socket.write("You connected.");
      clients.push(socket);
  });
  
  // .. later when I want to close
  server.close();
  clients.forEach(function(client) {
      client.destroy();
  });
  </code></pre>
  
  <p>Is it the same for Tcp? Or should I do anything differently?</p>