Comprehensive fix for socket errors.