Added some code to test for failed connections.

Re #13:

Here's some code that listens to the `"failed"` message from the server and deals sensibly with it (calls `connected()` with an error callback, stops automatic reconnection).

Does this seem like a reasonable approach?