Added: exception handling for socket errors