Communication architecture in mobile development (I)

Source: Internet
Author: User

Mobile development, or most of other software development, our programmers do nothing more than three things: getting data, displaying data, getting user events, and making corresponding feedback. In addition, due to the unstable network environment in mobile development, obtaining network data has become a bottleneck for many applications. This article will try to build a stable, efficient, and universal mobile development communication framework.

This article is based on the j2_environment and can be easily transplanted to other platforms.

The following is a step-by-step analysis based on my ideas:

1. Anyone who has worked in mobile development knows that communication will be completed in a separate thread. Do not explain the reason ......

2. Communication?: Request (Request, StructRequest), send a Request, get a Response (HttpHandler, HttpClient), and then get the Response (Response, StructResponse)

3. There are only two communication results: Success and Failure. If the communication is successful, the UI thread (HttpListener) should be notified to complete data painting. If it fails, there will be more situations. As a saying goes, there will be one beauty, but each ugly one has its own ugliness. In most cases, communication failures can be detected by HttpListener and fed back to the UI thread. But what if there is no response? Where is the program stuck? Obviously not. At this time, a timer listener (HttpMonitor) is required. When the communication times out, the communication will be abandoned.

The following shows the class diagram of the entire framework (I think the class diagram is ugly and cannot be used ......)

 

The first article is written here, giving you an overall impression. The next article analyzes the request block and uploads the source code.

Author: "Feng Xiaowei"

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.