catch error when sending on closed socket, fixes #38