Internal errors have codes > 600 since error codes 500-599 are server error codes.
Close JsonService streams and webSockets on errors.

Also handle NSStreamEventEndEncountered. Fixes #23 by improving
reporting on why the JsonService would stop.