tidy tcp error handling and close vs disconnect