added socket connection error handling