Signal an error if the socket closes out from under us

The server can close the socket summarily, for example if it decides
the client hasn't been keeping up heartbeats. To detect this I listen
for the 'end' event on the socket. This needed a bit of extra plumbing
in the test harness.

This changes the semantics of 'error' and 'close'; previously, only
one was ever emitted from a connection or channel. However, Node.JS's
streams don't behave like that, so I've changed it. 'close' is always
emitted, and 'error' beforehand if the closure is due to a problem.