DNS optimization knowledge collation for Android network interaction

Source: Internet
Author: User

DNS optimization knowledge collation for Android network interaction

Previous work, often encountered DNS resolution problems caused by network interaction operation is not normal.

In many mobile development processes, the URLs that interact with the server are usually included with the domain name. In the actual network interaction process, the first step will need to DNS resolution of the domain name.

In a complex network environment, DNS parsing can take a long time, or even fail to parse. This is often the case.

So the optimization of this step is very important.

There is a solution called: IP direct connection

is in the process of network interaction, skip DNS resolution of the domain name, directly with IP for network interaction. Can avoid this big trouble.

In response to this scheme, Httpdns has been derived from the following several famous:

    • Dnspod d+ Mobile resolution service d+ Free
    • Ali
    • Sina

The basic implementation of these methods is:

    1. Send the domain name to the HTTPDNS server and get the IP address of the domain name
    2. Replace the IP address with the domain name for network access

Of course, there is a lot of detail in every step.

One important point is that for an IP host to mount multiple servers, the host header needs to set the domain name when using IP direct connection

The code is as follows:

    public static HttpURLConnection gethttpurlconnection (String urlstring)            throws ioexception {        url url = new URL ( urlstring);        String originhost = Url.gethost ();        HttpURLConnection Conn;        String Dstip = Httpdnsservice.getipbyhost (Url.gethost ()); Here gets the IP address        if (dstip! = null) {            LOG.D ("Httpdns Demo", "Get IP from Httpdns," + url.gethost () + ":" + dstip); 
   urlstring = Urlstring.replacefirst (Url.gethost (), dstip);            url = new URL (urlstring);            conn = (httpurlconnection) url.openconnection ();            Set HTTP request header host domain            conn.setrequestproperty ("host", originhost);//This is the setting of host            return Conn in head;        } else {            log.d ("Httpdns Demo", "degrade to local DNS.");            Return (HttpURLConnection) url.openconnection ();        }    }

  

For more content and introduction, you can refer to the following article:

    • http://blog.csdn.net/a345017062/article/details/38047595
    • The new idea of global accurate flow dispatching of "Goose Factory Network Affair"-httpdns Service explanation
    • Https://github.com/CNSRE/HTTPDNSLib

DNS optimization knowledge collation for Android network interaction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.