title: Clojure TCP Server with Aleph
body: <p>I am attempting to write a simple TCP server using Aleph.  Everything works fine, except I am unsure of how I should detect when a channel has been closed.</p>
  
  <p>From the <a href="https://github.com/ztellman/aleph/wiki/TCP" rel="nofollow">documentation</a>:</p>
  
  <blockquote>
    <p>When the client closes the connection, both sides of the channel will be immediately sealed.  The final message from the channel will be nil</p>
  </blockquote>
  
  <p>However, I never seem to receive this final <code>nil</code> message.  If I inspect the channel, I do see that it has been closed.  Here is my code:</p>
  
  <pre><code>(use 'lamina.core 'aleph.tcp 'gloss.core)
  
  (defn process-msg [ch msg]
    (if (closed? ch)
      (println "Channel has been closed") ;This never happens
      (do-some-processing msg)))
  
  (start-tcp-server
    (fn [ch client-info]
      (receive-all ch
        (partial process-msg ch))
    {:port 10000, :frame (string :utf-8 :delimiters ["\n"])})
  </code></pre>
  
  <p>Should I be doing something differently?  Is my frame keeping the nil message from being processed?  I could have a separate thread monitoring my channels and checking whether or not they have been closed, but this seems like a poor design.  I would prefer to use Aleph, but right now its looking like I will need to use a raw Netty handler.  Using Netty directly would be fine, but I'd prefer to use Aleph if possible since it feels a little more idiomatic.</p>