The server returns a list of optimal IP addresses. These addresses have the same weight on the server and are not sorted. The optimal IP address for a client depends on its network environment.
HTTPDNS is a recursive domain name resolution service. The IP addresses that it provides are retrieved from the authoritative DNS. To obtain optimal results, the authoritative DNS must update its scheduling policy. This policy should return IP addresses from multiple nearby nodes based on the client's IP address. The client can then probe these addresses and select the optimal one.
Android and iOS SDKs V1.1.5 and later support IP optimization. After you configure this feature, the SDK tests the speed of the returned IP addresses during domain name resolution and dynamically sorts the list. This process ensures that the first IP address in the list has high availability.
If you do not use the SDK, you can probe the IP addresses to find the optimal one.
IP optimization interface code examples
Android:
ArrayList<IPRankingBean> list = new ArrayList<IPRankingBean>();
list.add(new IPRankingBean("www.aliyun.com", 8080));
new InitConfig.Builder().setIPRankingList(list);This method was added in version 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 = 'Replace this with the Account ID from the Alibaba Cloud HTTPDNS console'
export default class EntryAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
httpdns.configService(ACCOUNT_ID, {
context: this.context,
// ************* IP optimization configuration begin *************
hostConfigsForIpRanking: [{
host: 'www.aliyun.com',
port: 80
}]
// ************* IP optimization configuration end *************
})
}
// Other code omitted
}