7.app and app back-end communication

Source: Internet
Author: User

There are often developers asking: is the app and backend communication an HTTP protocol or a private protocol? Is it a long or short connection? By reading this article, help you to remove the above questions.


(1) Is it an HTTP protocol or a private protocol?

In spy TV dramas, often can see the spy's letters are using the code, even if the letter was intercepted by the enemy is not afraid, need to spend a certain amount of time, the enemy can solve the secret of the letter.


In film < Avatar, James Cameron even found a linguist to enhance the authenticity of the story, creating a language for Na ' VI. When we saw this movie, we couldn't understand what the Na ' an aliens on Pandora were saying. There are about 1000 words in Na ' VI, and the only person in the world who can master its grammar is the one who created the language, and even if he is still learning how to speak na ' vi more fluently.


If the spies are using Chinese that everyone knows, the enemy intercepts the letters and can immediately know what's inside them.


If the Na ' an aliens on Pandora are speaking Chinese, then a lot of people will know what they mean when they hear it.


Similarly, the app and backend communication can be divided into common language communication, or the use of code communication two ways.


There are many common languages, such as English and Chinese, and in the network communication, there are many common protocols, of which HTTP is the most widely used. If it is a private agreement, it can only be designed by itself.


HTTP is the most convenient, if it is a private protocol, including the package and disassembly of the Protocol, the workload, front-end programmers and back-end programmers have to add a lot of extra work. And the private protocol is highly demanding for programmers, and is not suitable for developers who are transferred from a Web site. Unless it's a hands-on tour, it's good to use HTTP.


(2) Does the app and server communicate using long or short connections?

If you call another person's phone by phone now, mobile phone calls are very cheap (or even negligible), but there are two places to note:


1. A mobile phone can only answer a phone at the same time.


2. A mobile phone before answering the phone is very troublesome, to dial, to wait for the answer, it takes a while.


App and server communication using a long connection or a short connection this problem, can be equated with the phone model above, is to keep the call, or if there is a need to dial calls this problem?


When the app and server communication use long connection, it is equivalent to keep the call, the server can maintain a limited number of communications, if the communication is full, then the other apps can not communicate with the service side. This mode of communication, most of the use of sockets or websocket connection for a long time, the requirements of the programmer is relatively high, the development of more difficult, in addition to hand-travel and chat push service, not recommended to use.


When the app and server communicate using a short connection, it's equivalent to dialing calls when needed. This mode of communication, in conjunction with the HTTP protocol, is now the mainstream of communication, the development of high efficiency, there are a large number of third-party resources, using a very broad, recommended use this way.


(3) How does the app and backend communicate?

I believe that we have used the bank teller machine (ATM) to check the balance, transfer, withdrawals and other operations.


When the teller machine withdrawals, we enter the amount to be withdrawn, the money will come out every other time, if there is any problem can not be withdrawn (for example, more than the withdrawal amount limit), the screen will also show the wrong information.


Throughout the process, we just enter the amount and get the results (the withdrawals are successful or unsuccessful), and as for how the teller machine is handled inside, we don't need to bother.


Teller machine This method of shielding the internal processing is very convenient for our use.


The same, in the backend, also only provides a series of functions for the app to use, this series of features in the form of API.


API Definitions: APIs (application Programming Interface, application programming interfaces) are pre-defined functions designed to provide applications and developers the ability to access a set of routines based on a piece of software or hardware without having to access the source code, Or understand the details of the internal working mechanism.


When the app calls the API, only the following 3 points need to be clarified:


1. What does this API do (in the case of teller machines, the withdrawal function, or the balance, or the transfer)


2. Know what to enter (in the case of teller machines, withdrawals are to be entered into money)


3. Know what the result is (in the case of a teller machine, the withdrawal is a success or failure)


As for how the API is handled internally, the app doesn't need to be ignored.


API, usually called in the form of HTTP, through the HTTP incoming parameters, return the results. The results are generally returned in JSON format, because the JSON format is supported by many computer languages and saves traffic.


--------------------------------------------------------------------------------------------------------------- ------------

Open the total list of articles in the Link app backend series to see all the original "app backend" articles I've published.


"Author" Zeng Jiansen

"QQ" 190678908
"QQ Group" 254659220
"public number" Appbackend
"Sina Weibo" @newjueqi
"blog" Http://blog.csdn.net/newjueqi



7.app and app back-end communication

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.