The application of mobile network communication channel in development

Source: Internet
Author: User

This piece of article from Http://blog.csdn.net/andywuchuanlong, reproduced please explain the source, thank you!

This article will be about how to choose the mobile communication channel in the project development, this so-called communication refers to the mobile phone terminal and the server data exchange, and the channel refers to the mobile phone terminal and the server for data exchange method.

As an example of Android project development, there are several types of communication tools available in Android: HttpURLConnection, HttpClient, sockets, and so on. But are these tools available for all channels?

There are several communication channels for mobile phones:

1, WLAN: Wireless network channels, such as WiFi, when the mobile phone using this channel way to the Internet, will directly request the server.

2, APN: Mobile APN access Point, is the base station, and this access point way there are probably two kinds:

A) WAP mode: This is a regional channel way, mainly for value-added services, such as China Mobile's proxy IP is 10.0.0.172, port is 80, the telecommunications port is 200. This way the Internet, through the WAP Gateway (proxy), the operator will first intercept, filter out the user's request, and then turn to the real resource server. More steps than usual, it also reduces the speed of the Internet. Go WAP gateway Not all communication tools are available. HttpURLConnection seems to be no, network stability is very poor. If you use WAP on your mobile phone, you need to configure it in your code.

b) NET method, which requests the server directly.

The following shows how the code chooses the communication channel.

    First of all, what kind of communication channel do you decide to walk? is WiFi or APN,APN in the WAP special access network type: WiFi or Mobile, determine which APN is selected, get the APN proxy information public static Boolean checknet (Context con               Text) {//judgment: WiFi link Boolean iswifi = iswificonnection (context);               Judge: Mobile link Boolean ismobile = ismobileconnection (context);                    If mobile is in the link, determine which APN is selected if (ismobile) {//APN is selected, whether the agent information has content, if there is a WAP mode                    READAPN (context);//Determine which APN is selected} if (!iswifi &&!ismobile) {               return false;          } return true; }/** * APN is selected, the agent information is content, if there is a WAP way * * @param context */PR ivate static void Readapn (context context) {Uri Preferred_apn_uri = Uri.parse ("Content://telephony/carriers /PREFERAPN ");//4.0 simulator screen out this permission//operation contact similar to contentresolver resolver = Context.getconTentresolver ();               Determine which APN is selected by cursor cursor = resolver.query (Preferred_apn_uri, NULL, NULL, NULL, or NULL); if (Cursor!=null&&cursor.movetofirst ()) {globalparams.proxy=cursor.getstring (cursor.getColumnInd                    EX ("proxy"));               Globalparams.port=cursor.getint (Cursor.getcolumnindex ("PORT")); }          }
           HttpClient: Set proxy information public                   Httpclientutil () {               client = new Defaulthttpclient ();               Determine if you need to set proxy information               if (Stringutils.isnotblank (Globalparams.proxy)) {                    //Set proxy information                    httphost host = new Httphost ( Globalparams.proxy, globalparams.port);                    Client.getparams (). Setparameter (Connroutepnames.default_proxy, host);               }          }

The application of mobile network communication channel in development

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.