Share more tcp-handling code between server and client connections. Makes sure clients emit 'close' on Node v0.10.