Use a safe_foreach in socket delivery