Android message push technology androidpn

Source: Internet
Author: User
Tags android push notification

Message push is becoming increasingly popular. Now Baidu also provides message push services. You can search for them.

There are three ways to push data from the server to the android client:

1. Round Robin, ApplicationProgramYou should establish connections with the server in stages and check whether new messages arrive. You must implement communication with the server yourself, 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. SMS(Obtain commands from the server by sending text messages and parsing the text message content). This problem is that it is difficult to find a free gateway to send text messages;

3. Persistent connectionsMainly socket communication, which solves the performance problem, but the power consumption problem still fails to be solved.

Here, we mainly introduce the third type of push by means of persistent connections. Currently, there are four mature and timely messaging protocols, and XMPP is undoubtedly the most popular. XMPP is an XML-based transfer protocol with high flexibility and scalability. It transfers complexity from the client to the server. You can find a lot of XMPP data on the Internet. I will not repeat it here. Otherwise, the more you pull. In short, XMPP has the following major advantages:

1. Distributed anyone can run their own XMPP server, which has no master server

2. High security. Reliable security using SASL, TLS, and other technologies

3. Open source, easy to learn and understand

4. There is no doubt that cross-platform data is transmitted using XML

After that, let's get down to the point. The Java Development Based on XMPP has an open-source framework, smack, which encapsulates some implementation of XMPP. However, it cannot be used directly on Android. Because Android lacks some Java class libraries, a simplified version of asmack is born. It is an android smack specially designed for Android. The birth of another open-source framework is to implement persistent connections with the server end based on the reference of smack to push the server to the client, that is, Android push notification (androidpn for short.

Androidpn integrates asmack on the client. In this way, you can easily establish a socket connection with the server based on the XMPP protocol. In the androidpn client, the connection management class is xmppmanager, which is used to manage the connection information, such as the XMPP port, IP address, logon username and password, and connection maintenance. Why are there usernames and passwords? I have to mention the specific details of XMPP. The communication between the server and the client is based on a session. When a session starts, the server port number is specified and the information mentioned above is sent to the server, how do I send messages? It is transmitted as the <stream> root node. The End mark is sent only when the server and client are closed </stream>. The client only uses the XMPP protocol to receive messages, and all other operations are handed over to the server, such as managing connections and saving messages, which greatly reduces the burden on the client. How is the message response from the client and the server implemented? To identify the XMPP protocol by using an ID, you can view the XMPP protocol for details.

After registration and binding, the server establishes a connection with the client, and the client is only responsible for receiving messages. So when we apply androidpn, the client will be very simple. What does androidpn do on the server?

For server demonstration, androidpn mainly uses spring and hibernate technologies. It is mainly used to display the user status and send information. The following is the server interface:


We mainly want to talk about XMPP management. In the source code of the server, an org.androidpn.server.xmpp.net. connection class, mainly refers to the XMPP connection on a server. Note that it is only one. It can ensure that when the server is closed, a </stream> flag is sent to the client to notify the connection to be disconnected, you need to reconnect.

Org. androidpn. server. XMPP. session. sessionmanager allows you to manage all sessions, such as disconnecting, deleting sessions, establishing connections, and adding sessions.

While managing socket connections, androidpn adopts the Mina framework for management. The advantage of Mina is that it changes our traditional method of managing sockets. For example, if a socket is not set up to open a thread, mina can manage n users in multiple threads. It is undoubtedly of great benefit to handle highly concurrent pushing.

The rational use of listeners to manage sessions is also an advantage of androidpn. In terms of security, the TLS (Secure Transport Layer) policy has been developed, but security authentication has been adopted. These aspects have all done well.

Of course, the inevitable 30-second heartbeat package is still essential.

In short, the advantages of using androidpn are as follows:

1. Use the fully open XMPP protocol for data transmission (QQ, MSN, Gtalk, etc. are all using this Protocol );

2. Good framework support (asmack, a push framework specifically for Android, and Mina, a framework for managing sockets, are all mature products );

3. Fully OpenSource code(We can modify it based on androidpn to meet any of our needs );

4. greatly reduced the client'sCodeTo reduce the difficulty of Android development.

The disadvantage is self-evident. Too many frameworks are used. If you want to change some specific implementations, the migration may start the whole body.

 

You can try it. You can find androidpn on the Internet and download it by yourself,

Part of this article is taken from the network.

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.