Now more correctly handling socket errors, also now consistently emitting the close event.
Closes #137
Closes #138
Closes #127
Closes #128
Fixes bug inadvertently introduced by pull request #129