Fix socket.error handling

This closes #4