title: socket.setTimeout() in node.js
body: <p>I trying to implement http server based on net module.<br/>
  I need to implement keep-alive in it, so I call to <code>sock.setKeepAlive(true)</code> and then <code>sock.setTimeout</code> to close the socket after 2 sec timeout.<br/>
  Here Is my code:<br/></p>
  
  <pre><code>var server = net.createServer({ allowHalfOpen: false},socketListener);
  
  function start(port){
      server.listen(port,'localhost');
  }
  
  function socketListener(sock){
      sock.setEncoding("utf8");
      sock.setKeepAlive(true);
      sock.setTimeout(2000,function(){
          sock.end("HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n");
      });
      sock.on("data",responser.responserCreator(sock,httpParser,baseDir,stat));
  }
  </code></pre>
  
  <p>But when I open a browser and to <code>http://localhost:1234/profile.html</code> for the first time it works fine, but if I make a refresh after 2 sec it throws an exception - </p>
  
  <blockquote>
    <p>Error: This socket has been ended by the other party at Socket.writeAfterFIN [as write] (net.js:274:12)</p>
  </blockquote>
  
  <p>If I comment the timeout everthing works fine.<br/>
  What wrong in my code?</p>