Improve socket error handling in MQTT client
Fixes #155