首先说明,返回的IP是服务器这边筛选出的最佳IP列表,在服务器端权重是一样的,也就是没有顺序,具体到您需要客户端最优IP,是要结合客户端网络环境来确定的。
另外需要关注: HTTPDNS 本身是递归域名解析服务,IP源来自权威DNS返回结果。因此,在实际应用中要想达到最佳效果,需要权威DNS配合更新调度策略,根据 client_ip 返回附近多节点IP,供客户端探测选择。
如果使用SDK的话,Android或iOS SDK V1.1.5及以上版本支持IP优选,设置该接口后,如果解析了相应的域名,则SDK会对返回的IP进行测速,对返回的列表进行动态排序,以保证第一个IP是可用性较好的IP。
如果不使用SDK,则需要进行探测,来进行IP优选。
使用IP优选接口示例代码如下:
Android:
ArrayList<IPRankingBean> list = new ArrayList<IPRankingBean>();
list.add(new IPRankingBean("www.aliyun.com", 8080));
new InitConfig.Builder().setIPRankingList(list);
说明
2.3.2版本新增的方法。
iOS:
HttpDnsService *httpdns = [[HttpDnsService alloc] initWithAccountID:XXXX];
NSDictionary *IPRankingDatasource = @{
@"www.abc.com" : @80,
@"www.cba.com" : @443,
@"www.bac.com" : @443
};
[httpdns setIPRankingDatasource:IPRankingDatasource];
Harmony:
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { httpdns } from '@aliyun/httpdns';
const ACCOUNT_ID = '这里需要替换为阿里云HTTPDNS控制台的Account ID'
export default class EntryAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
httpdns.configService(ACCOUNT_ID, {
context: this.context,
// ************* IP优选配置 begin *************
hostConfigsForIpRanking: [{
host: 'www.aliyun.com',
port: 80
}]
// ************* IP优选配置 end *************
})
}
// 省略其它代码
}
该文章对您有帮助吗?