Close socket
Version 1.5.0: cleaned up exception handling