Report connection errors to JavaScript.

Instead of just calling logger.error() (and subsequently alert2() in JS)
there's now on_socket_error() that tells JS code that there was an error
and the socket is now closed.

This is done so that JS can change the connection status to disconnected
instead of thinking it's still connecting until the user clicks the
connect button twice.