Extract the IO and Messages streams and flesh them out to implement backpressure.
Emit 'end' from the messages stream when the socket's onclose event runs.