title: TCP stream handling in node.js
body: <p>I have a code like the following. It works correctly at the first time. After that I get a <code>write after end</code>. I understand what the problem is, but somehow I don't understand how to do it correctly. I so far tried unpiping and using Half Open Connections. I feel out of ideas and out of examples.</p>
  
  <pre><code>server = require('net').createServer (input) -&gt;
    input
      .pipe(someTransformObjectStream)
      .pipe(foo)
      .pipe(bar)
  </code></pre>
  
  <p>Stack Trace:</p>
  
  <pre><code>events.js:72
      throw er; // Unhandled 'error' event
  
  Error: write after end
    at writeAfterEnd (_stream_writable.js:130:12)
    at someTransformObjectStream.Writable.write (_stream_writable.js:178:5)
    at write (_stream_readable.js:583:24)
    at flow (_stream_readable.js:592:7)
    at Socket.pipeOnReadable (_stream_readable.js:624:5)
    at Socket.EventEmitter.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:408:10)
    at emitReadable (_stream_readable.js:404:5)
    at readableAddChunk (_stream_readable.js:165:9)
    at Socket.Readable.push (_stream_rea
  </code></pre>