#518: Send roughly-appropriate codes and close the WebSocket connection when errors are encountered.
#518: Close connection on end-of-stream.