Added missing socket import for exception handling