add try-except blocks for a socket connection