Expanded error handling in socket communication.