Mobile phone message push mechanism [reprint]

Source: Internet
Author: User
[Pin to top] mobile phone message push mechanism

As the company wanted to develop an android message push function, I conducted a survey and found that there was no centralized explanation on the Internet. I collected some information on the Internet and summarized it myself.

There are four types of message reminders: fixed window, pop-up window, SMS, and push information. The following describes the push information mechanism and technical implementation.

First, we need to know what push information is?

Information Push is a new technology that uses certain technical standards or protocols to regularly transmit user information on the Internet to reduce information overload. Push technology automatically transmits information to users to reduce the time used for searching on the network. It searches and filters information based on users' interests, and regularly pushes it to users, helping users efficiently discover valuable information.

Simply put, Information Push means that the server actively sends information to the client and the client receives the information. For example:

Benefits of using push information:

1. Saving your battery power.
2. You can push notifications to inform your usersProgramSome interesting things happen, even if the program is not running.

Currently, many applications use the push mechanism:

Including Sina Weibo, pushing latest news from friends, moji.com, Netease news, pushing important news, and the latest stock information pushed by mobile phone stock trading in huashun ;, push the latest voice. Gmail and Gtalk push the latest Mail Information and Im information.

 

Next, let's take a look at the push mechanism of mainstream mobile phones.

The working mechanism of iPhone (Apple) can be summarized as follows:

The message push mechanism was launched after iPhone 3.0. The principle is that messages are processed by servers in a unified manner.

 

In the figure, provider refers to the push server of an iPhone software.ArticleI will use Java as the provider.

Apns is the abbreviation of Apple push notification service (Apple push server). It is an apple server.

It can be divided into three stages.

Stage 1: the Java application packs the message to be sent and the identifier of the target iPhone and sends it to apns.

Stage 2: apns searches for the iPhone with the corresponding identifier in its registered PUSH Service iPhone list and sends the message to the iPhone.

Stage 3: The iPhone transmits the sent message to the corresponding application, and a push notification is displayed according to the settings.

We can see from.

1. First, the application registers for message push.

2. for iOS and apns servers, devicetoken is required. The application accepts devicetoken.

3. The application sends the devicetoken to the push server.

4. The server program sends a message to the apns service.

5. The apns Service sends messages to the iPhone application.

Apns maintains a persistent heartbeat connection with the iPhone for 15 minutes, and maintains the connection between the mobile phone and the server. Otherwise, the mobile phone will initiate a connection until it is connected to the server. The program does not need to enable and actively check for updates in real time. When an apns message is received, the push message dialog box is displayed on the iPhone with sound. You can select "View" or "close ". Even if the user is offline, the user activates the program after receiving the message and then downloads the email or recording through the Application Server link.

 

The push mechanism of WP7 (Microsoft) is as follows:

WP7 also has a corresponding push service, regardless of whether the program is enabled or not, you can push toast notification on the top of the interface, and display 10 seconds. The push client of WP7 is responsible for server interaction. When a message is received, it is sent to the corresponding application, without the need for the application to maintain a process. If the app is pinned to the homepage, the server pushes the tile notification to change the tile's background image, number, and title attributes. The pop-up box native push (raw notification) only allows real-time update of the interface when the application is enabled.

 

 

 

The push mechanism of WebOS (Blackberry) is as follows:

 

We can see that the data push on the BlackBerry Application Platform can be divided into six steps in the whole, in chronological order:

Step 1: The application server sends a push request to the MDS/BES server. The request sent is an HTTP request.

Step 2: Check the relevant configuration database on the MDS/BES server to check whether the request sent by the Application Server is a valid request. In addition, the MDS/BES server determines whether to receive the request based on resource conditions. The determination of whether to receive the request is also discussed in detail in the next section.

Step 3: The MDS/BES server returns a message to the application server, notifying the application server whether to accept the request. The returned message is returned to the application server as an HTTP response.

Step 4: The MDS/BES server pushes data to the handheld device

Step 5: The handheld device processes the data and returns a confirmation message to the MDS/BES server.

Step 6: MDS/bes determines what asynchronous messages are returned to the Application Server Based on the messages returned by the handheld device. This step does not necessarily happen, but may not happen depending on the push request.

 

 

Blackberry push is the earliest and earliest application on emails, and the BlackBerry push mechanism is also the best and safest mechanism for encryption.

 

Next we will introduce in detail the android push mechanism:

Android (Google ):

First, we will introduce the push of Google's official application:

1) if you have a new Gmail email, the mobile phone can immediately receive the email notification. There may be a latency of 2 to 3 seconds in the middle, and it is usually very timely;

2) If your contact is associated with Google contanct, you can use a desktop browser to access Gmail, modify the contact information, and soon the new contact information will be synchronized to your mobile phone.

In Google I/O 2010, we introducedAndroid cloud to device messaging (c2dm)Service, c2dm) has been released as part of Android 2.2. C2dm allows third-party developers to develop related applications to push a small amount of data messages to users' mobile phones. The Mechanism is as follows:

 

Android cloud to device messaging (c2dm) is a service that helps developers send data to Android applications from servers. The Service provides a simple and lightweight mechanism that allows the server to notify mobile applications to communicate directly with the server, so that the server can obtain application updates and user data. The c2dm service processes transactions such as Message Queuing and distributes these messages to applications running on the target device.

How to enable c2dm:

1. Mobile Devices: Android must be running and market must be installed. At least one Google account is logged on to the device.

2. SERVER: your own server

3. c2dm server: Google Server

Authorization Mechanism:

1. sender ID: a Google account used to indicate the developer's identity, suchHxzhoupeng@google.com

2. Application ID: pacakage name in manifest. xml. Used to identify applications

3. Registration ID: when the application registers with the c2dm server, the c2dm server returns this ID. After the application obtains this ID, it should tell its own server, your server stores this ID in the database to tell the c2dm server to mark the client.

4. Google user account: to use the c2dm service, you must have a Google account.

5. Sender auth token: authentication for communication between your server and c2dm server.

 

The application sends intent, Com. google. android. c2dm. intent. register with the c2dm server by attaching your senderid and appid. After successful registration, you can receive the registration intent and obtain the registration ID, which will be changed by c2dm, therefore, this registration intent may be received multiple times. Remember to store and send it to your server.

 

Through comparative research, we found that the c2dm mechanism has the following Disadvantages:

1. c2dm is built into the Android 2.2 System and cannot be compatible with the old 1.6 to 2.1 systems;

2. c2dm depends on the c2dm server officially provided by Google. Due to the domestic network environment, this service is often unavailable. If you want to use it well, our app server must also be abroad, this may not be implemented by every developer ;.

 

In addition to c2dm's implementation of the android message push mechanism, there are also the following solutions:

1. Polling: Applications should connect to the server and check whether new messages arrive. You must implement communication with the server, such as Message Queuing. In addition, you also need to consider the polling frequency. If it is too slow, it may lead to delay of some messages. If it is too fast, it will consume a lot of network bandwidth and battery.

2. persistent connection: this solution can solve the performance problem caused by polling, but it will still consume the cell phone's battery. The push service of apple works well because each mobile phone only maintains a connection with the server. In fact, c2dm works like this. However, this solution also has shortcomings, that is, it is difficult for us to implement a reliable service on the mobile phone. The Android operating system allows you to kill system services with low memory, so your notification service may be killed by the operating system.

This method can also be achieved through the "come" (based on the HTTP persistent connection "server push" technology) persistent connection. For details, refer to http://www.ibm.com/?works/cn/web/wa-lo-comet/, but this is not the same method,

In Android, the XMPP protocol should be used to push Android information:

First, we will introduce XMPP Based on the Extensible Markup Language (XML) protocol, which is used for instant messaging (IM) and online detection. This agreement may eventually allowInternetThe user sends instant messages to anyone else on the Internet. For details, refer:

Http://zh.wikipedia.org/zh-cn/XMPP

The bottom layer of Google's official c2dm server is also encapsulated using the XMPP protocol.

AndroidpnIs an open-source Java Android push notification implementation based on XMPP protocol. It contains the complete client and server. This server is basically in another open source projectOpenfire. Its implementation is as follows:

The androidpn client needs to use a Java-based open-source XMPP protocol package.AsmackThis package is also an open-source project based on openfire.SmackBut we don't need to compile it ourselves. We can use asmack. jar in the androidpn client directly. The client uses the xmppconnection class provided in asmack to establish a persistent connection with the server and use this connection for user registration and logon authentication. This connection also receives notifications sent by the server.

The androidpn server is also implemented in Java. It is based on the openfire open source project. However, its Web part adopts the Spring framework, which is different from openfire. The androidpn server consists of two parts. One is the XMPP service listening on port 5222, which is responsible for communicating with the xmppconnection class of the client. It serves as a user registration and identity authentication, and sends push notification messages. In addition, a web server uses a lightweight HTTP server to receive users' Web requests. The server architecture is as follows:

The top layer includes four components: sessionmanager, auth manager, presencemanager, and notification manager. Sessionmanager is responsible for managing sessions between the client and the server. Auth manager is responsible for client user authentication management, presence manager is responsible for managing the logon status of client users, and icationicationmanager is responsible for pushing messages from the server to the client.

The server interface is as follows, which corresponds to the above functional modules:

 

After sending the message, we can see the received message on the mobile phone:

The biggest advantage of this solution is simplicity. We do not need to rely on the operating system version like c2dm, nor worry about the unavailability of Google servers one day. With XMPP protocol, we can further expand the Protocol to achieve more comprehensive functions.

Currently, this scheme can only be used to send text messages, but it is generally enough for pushing, because we cannot expect to get all the data through pushing. Generally, push only tells the Mobile Server that some changes have taken place. When the client receives the notification, it should take the initiative to obtain the latest data from the server. This is the complete implementation of the push service.

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.