Handle socket errors occurring before connection is established

The callback function to `connect` is not called if a socket error occurs before the connection is established (eg. the server is down, connecting to wrong URL, etc).

Fixing the issue by emitting a `failed` event if a socket error occurs on the socket before receiving the `connected` message.

Also setting the initial value of `_isReconnecting` to `false` to make the first call to the connect callback consistent with the subsequent calls, and moving the event listener test to a more appropriate place.