Handling closed socket