Study on the study of ANDROIDPN (II.) Source structure analysis

Source: Internet
Author: User

The main package structure of the server section is as follows:

among them, Org.androidpn.server.dao,org.androidpn.server.model and org.androidpn.server.service to use Hibernate link database and implement simple user login authentication, development can Replace it with our own authentication module. The rest of the package is the main implementation of the push.


Next package to see:

the classes in the 1.util package are used to load the configuration files in the resources, which can be specified in configuration files such as listening ports and SSL certificate directories.

The 2.ORG.ANDROIDPN.SERVER.XMPP package defines some exception types, mainly including the entry class Xmppserver, which is used to start and stop the server program.

3.org.androidpn.server.xmpp.auth package Inside is a number of certified classes, our own authentication module can be combined here with the ANDROIDPN.

4.org.androidpn.server.xmpp.codec is an XML file parsing package for the XMPP protocol, and messages received and sent by the server are routed through this package for XMPP protocol encoding and decoding.

The 5.org.androidpn.server.xmpp.handler package is primarily about handling messages, and we can define our own handler for different message types .

The 6.org.androidpn.server.xmpp.net package is responsible for maintaining a persistent connection to the client and implementing some transport methods for sending XMPP messages.

The 7.org.androidpn.server.xmpp.presence contains only the Presencemanager class, which is used to maintain the client's online status.

the Notificationmanager class inside the 8.org.androidpn.server.xmpp.push package contains an interface that sends messages to the client.

The 9.org.androidpn.server.xmpp.router packet is responsible for sending the received packet to the appropriate handler for processing, which is a routing packet.

The 10.org.androidpn.server.xmpp.session package defines a session that represents a persistent link, with each session containing state information for a connection.

11.org.androidpn.server.xmpp.ssl is a toolkit for SSL authentication of connections.


The entire process by which the server sends messages is mainly:

1. The push interface of the Notificationmanager is called.

2. Use SessionManager to find the appropriate client link in the current session collection.

3. Define your own XMPP message format and assemble it.

4. Send a message to the client via the corresponding session.


in this process we need to revise step 3, that is, we need to define and assemble our own XMPP messages, so that we can transfer the appropriate information to the client and facilitate client resolution. Note that when you create an element, the incoming namespace is matched to the namespace used by client parsing.



the process of receiving and processing messages on the server side is:

1.connection received packet, using ORG.ANDROIDPN.SERVER.XMPP.CODEC decoding.

2.router routes packet to the appropriate handler based on information such as the namespace of the packet.

3.handler for processing.

In development, you can define your own router and handler classes according to the format of the client sending messages, then register router in Packetrouter, and register Iqrouter in handler.


The main package structure of the client part is as follows:

This side contains the message of sending and receiving, parsing and the initiation of persistent connection, re-connect and other functions, very powerful, we develop completely without the bottom of the connection, do not worry about disconnection, you can focus on the development of business parts.

at the same time, the code structure is simple. Removal of the Android service and broadcast classes as well as some tool classes and constant classes are not discussed:

1.notificationiq,notificationiqprovider,notificationpacketlistener Three classes are responsible for parsing and processing messages received in the notification format.

2.XmppManager is the main controller, notificationservice through this class, in the background to maintain the ANDROIDPN connection.

3.persistentconnectionlistener,phonestatechangelistener,reconnectionthread.java Three classes are responsible for the state of the * * * and the disconnection.



We need to define 3 classes when we customize the message: The entity that defines the message in ***iq, the message into the ***iq entity in the ***iqprovider, the entity is processed in the ***packetlistener, the specific implementation can refer to the Notificationiq, Notificationiqprovider,notificationpacketlistener of three classes. After defining these classes, you will also need to register these 3 classes in Xmppmanager in the connection with the following code:

Connection.connect (); LOG.I (LogTag, "XMPP connected successfully"); Providermanager.getinstance (). Addiqprovider ("message", Constants.notification_namespace,new Notificationiqprovider ()); Packetfilter packetfilter = new Packettypefilter (notificationiq.class);//Packet Listenerpacketlistener          Packetlistener = Xmppmanager.getnotificationpacketlistener (); Connection.addpacketlistener (Packetlistener, Packetfilter);

When registering ***iqprovider, the incoming namespace needs to be consistent with the namespace used to assemble the message on the server in order to receive it correctly.


This article is from the "Old GE Technology Learning" blog, please be sure to keep this source http://ptghb.blog.51cto.com/3902848/1664720

Study on the study of ANDROIDPN (II.) Source structure analysis

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.