The push technology in Android, iOS, and Windows Phone _android

Source: Internet
Author: User

Push is not a new technology, which has become popular in the internet age. But with the advent of the mobile internet era, push technology appears to be more important. Because in a smartphone, push to a certain extent, can replace the use of many years of text messages, but also compared to text messages, you can show users more information (such as images, tables, sounds, etc.).

Implementations of push technologies typically use the way the server pushes messages to the client. This means that the client can send messages to all active clients at the server end by registering them with the user name, key, and so on.

In fact, in many mobile operating systems, the authorities provide them with a push scheme, for example, Google's cloud push, IOS, Windows PHONE7/8 also provide similar push. However, these push the solution of the server are abroad, there are some push services (such as Google's cloud push) at home for some reason is not very stable, so the domestic in recent years has sprung up a lot of specifically for the people to build push service.

This article will start with all kinds of popular mobile operating systems to introduce the implementation of the push technology. Of course, our main goal is to discuss the Android push technology.

One, the push technology of iOS

Apple offers a perfect push for iOS, and the rationale is that Apple is offering its own push server, called APNs (Apple push Notification Service, MAC push notification server). The client device (IPhone, ipad, etc.) directly establishes a long connection with the APNs. However, messages sent to client devices are not generated by APNs, but are generated in servers (called provider) that are provided by the user who needs to send the message, and then provider the message to APNs, which is then passed to the client device by APNs. That is, the message is first generated by provider, and then provider the message to the APNs, and finally to the client device by APNs. The process of message delivery is shown in Figure 1.

The delivery of this token (device token) is always accompanied by sending a message to a client device to receive a message. To provide a message service using APNS, the application needs to provide the necessary information to the iOS registry, which is related to the current device device Token,ios after receiving Devicetoken, will query this APNs Whether the token is registered on the APNs (all iOS devices need to register an account with the Apple server for the first time, otherwise they cannot download the app from Applestore, and of course not use the push service), if they are already registered, APNs will return this devicetoken directly to the application. After the application obtains this devicetoken, it means that APNs has allowed to push the message to itself, and then it needs to send the device token to the push server (Provider). Here the application has successfully registered itself in the APNs. You can now generate the message you want to push by provider, and then provider will send the message to the APNS server, and the APNS server sends the message directly to the application. This process is complicated, but looking at the description in Figure 2 will give you a better understanding of the process. Each process describes the preceding number indicating the order in which to send the time.

Second, the Windows phone push technology

Microsoft's push for window phone is similar to that of iOS, and it needs to be ready to push the server itself (which can be called the Cloud Service). Only indicates that the ID of the device has become a URI. There is a push Client Service (PCS) in window phone. All applications requiring push services need to communicate with the push Client service. Here is the basic step of window phone push, which the reader can see in Figure 3.

Step 1th: The application requests a push Notification URI (①) to the push Client service.

2nd step: If the current window phone device is already registered with a Microsoft server, push Client service will get push from MPNs (Microsoft Push Notification Service, Microsoft Push Notification Services) Notification URI and returns to the application that the push service is available (② and ③).

3rd Step: The application needs to send the push Notification URI to its own push server (Cloud Service) (④).

4th step: If you need to push the message, the Cloud Service sends the message to MPNs, and then MPNs delivers the message to the push client service, which eventually passes the message to the application (⑤, ⑥, and ③) by the push client service.

Third, the Android push program

Android's push program is more and more messy. For example, there are Google's official C2DM (Android Cloud to Device messaging), Third-party push services (such as Aurora Push), and push server programs implemented through various protocols (such as ANDROIDPN), Users can build their own push servers through these service-side programs. These push technologies are described in more detail later in this section, and this section first introduces the various push technologies that are often used in Android. Of course, these push technologies can also be used for other mobile devices, but because Android's official push service (C2DM) has some problems with its domestic use, Third-party push services based on Android are more than other systems, so this is mainly for Android.

The push technology is usually implemented in the following two ways.

1. Polling (Pull) mode

2. Persistent connection mode (service-side push mode)

Polling is the client at a certain time interval to continuously query the server for new messages. In this way, you must implement communication mechanisms with the server, such as message queues. But also consider the frequency of polling, if too slow may cause some message delay, if too fast, it will consume network bandwidth and battery. Therefore, most push services do not use polling methods.

The persistent connection is the push way, for the client, is a passive way, and the initiative in the server, when there is a message, the server to all registered to the push of the client push message. The advantage of this kind of push way is that it can guarantee real-time, and the client realizes simple. Of course, there will be shortages, for example, if a large number of clients maintain long connections to the server, consuming the resources of the servers. However, when messages are not pushed, these long connections become idle connections, and typically this connection consumes memory resources primarily. For example, 2 million users may consume dozens of GB of memory. Therefore, to build this push mechanism to use a good performance of the server.

There are many ways to implement a persistent connection, for example, you can use XMPP as a communication protocol. The main advantage of XMPP is that the protocol is mature, powerful and scalable. XMPP is more used in IM systems, and ANDROIDPN is also used in the XMPP protocol.

XMPP also has obvious drawbacks, for example, the protocol is complex, if the XMPP protocol can take a long time, but also because the XMPP is based on XML, resulting in data redundancy, resulting in mobile device charges, power consumption and other ills.

In addition to XMPP, you can also use the MQTT protocol, the main advantage of this protocol is simple, compact, scalable, resulting in the provincial traffic, power saving and other advantages, but also has C + + version of the server component RSMB. The disadvantage is that the protocol is not mature, and the implementation is more complex, and RSMB is not open source, the cost of deploying hardware is high.

Although C2DM services may not be stable in the country or some areas are not available, it is still necessary to introduce the principles of C2DM. However, it is best to use a third-party push service for applications that are used domestically, or to assume a push server.

C2DM and iOS APNs and window phone's MPNs are similar. You will also need to prepare a push server yourself and implement the push of the message through the following steps.

1th: The C2DM service on the mobile device needs to interact with Google's official C2DM server to verify that the current device is registered on the C2DM server and that if it is already registered, the C2DM server will return a registration ID to the client's C2DM service. (① and ②)

2nd Step: The client's C2DM service interacts with its own push server, passing the account number and the registration ID returned by the C2DM server to the push server. (③)

3rd Step: If you want to push the message, the push server sends the registration ID and the message to be pushed to the C2DM server, and then the C2DM server pushes the message directly to the client (cell phone, tablet device) (④ and ⑤).

Readers can understand these 3 steps in contrast to the figure 4来.

In addition to using the official push scheme, there are now several third-party push programs in the country, such as Aurora push (Jpush), Baidu Push and so on. Readers can also use these at the same time are usually free (may push multimedia data need to charge).

Related Article

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.