(Part of the text from the network)
XMPP protocol:
Xmpp:the extensible Messaging andpresence Protocol.
Chinese full name: Extensible Communication and presentation protocol.
Summary: Extensible communication and Presentation Protocol (XMPP) can be used for streaming XML data in service class real-time communication, presentation, and demand response services.
XMPP (Extensible Message Processing Field Protocol) is an Extensible markup language (XML)-based protocol that is used for instant messaging (IM) and online probing.
It facilitates quasi-immediate operation between servers. This agreement may eventually allow Internet users to send instant messages to anyone else on the internet,
make their operating system and browser different.
The main notable advantages of XMPP are the following:
1, distributed anyone can run their own XMPP server, it does not have a primary server, the client simple
2, security is very high. Reliable security using technologies such as SASL and TLS
3. It is open source, easy to learn and understand
4, cross-platform undoubtedly, the use of XML data format for transmission
ANDROIDPN:
Androidpn:android pushnotification (Chinese name: Android message push).
The XMPP protocol-based Java development has an open source framework, which is smack, which mainly encapsulates the implementation of some XMPP implementations. On the basis of quoting smack
Implementation and server-side persistent connection to the server to the client push, that is ANDROIDPN. The ANDROIDPN integrates smack on the client.
This makes it easy to simply set up an XMPP protocol-based socket connection to the server side. So ANDROIDPN can be said to be using the smack framework
of open source projects.
ANDROIDPN Use Benefits:
The benefits of using ANDROIDPN are as follows: the use of a fully open XMPP protocol for data transfer (Qq,msn,gtalk, etc.).
Good framework support (specifically for Android-generated push frame smack, and good management of the socket framework Mina, are very mature products);
Fully open source code (we can modify it on a ANDROIDPN basis to meet any of our requirements changes), greatly reducing the client's generation
To reduce the difficulty of Android development.
ANDROIDPN Technology Implementation:
(here does not say download source after how to operate, online tutorials a lot)
The client establishes a socket connection with the server.
ANDROIDPN Client to manage connection information such as XMPP port, IP (domain name), login username password, and maintenance of the connection (timed
The Send connection request keeps the connection not invalidated). The communication between the entire server side and the client is based on a session (session) process, where the conversation begins, first
Specify the port number of the server, and then send the message to the server side, and send the messages to the server:<stream> root node to start delivery, only in the service
End tag </stream> is sent when the service and client are closed. The only thing that the client uses with the XMPP protocol is to receive messages, and all
Other operations are given to the server, such as administrative connections, message storage, and so on, which greatly reduces the burden on the client.
ANDROIDPN server-side ,the main technology used by ANDROIDPN is spring and hibernate. Save the user information to the database and do the verification, mainly to
Show user status and send information. When the server shuts down, sends a </stream> tag to the client, tells the connection to disconnect, the client needs to be heavy
New connection. When managing the socket connection, ANDROIDPN uses the Mina framework for management, and the Mina's advantage is that it changes the way we manage sockets, such as opening a thread for each socket, and Mina
Multiple threads can be implemented to manage N multiple users (this sentence is not too clear,
Who knows to leave a speech, thank you very much). There is no doubt that there is a huge benefit in dealing with high-concurrency pushes.
In the process of data transmission, information processing takes the form of an XML section, which typically uses IQ (info/query), message (message),
Presence (online presence detection).
But Androippn doesn't seem to be using a message (perhaps I understand the error), from the server to the client and the client to the server's IQ package.
In addition, the XML transfer process has a type can be set,get,result,error four types, I personally understand is: Set refers to request update (change) processing
(such as push messages from server to client, registered users), get refers to fetching data (such as a friend list), result refers to the answer to the client after the request is updated
(If the login is successful to tell the client, see Clientsession in the CreateSession () method), error obviously refers to the error, generally means to tell the client to disconnect
Connection.
Long Connections and reconnection:
1. The client first connects to the server to establish a socket connection if the server needs to turn off return </stream> or an error indicating
The stream is returned to the client, and the client initiates a timed re-thread.
2. When the local connection server fails, a timed reconnection thread is started.
3. Local monitoring of network information, if the network is not available, will also start the re-connect process.
4. After successful connection, listen for socket connection status, if disconnected, start the reconnection process.
Note: 1) It is said that the firewall may turn off inactive connections, so it is said that the connection will be sent to the server heartbeat (keeplive).
Main file functions:
Client:
Demoappactivity Program Entry Activity
ServiceManager Service Manager, controlling the start and stop of background services
Notificationservice initialize the broadcast, and register the broadcast; Initialize thread send start connection broadcast and other
Xmppmanager defines the method that invokes the Asmack library, making the connection and its other.
Connectivityreceiver connecting the broadcast receiver, calling the Xmppmanager connection method
Persistentconnectionlistener re-connected monitoring, called by Asmack, is registered at connection time
Phonestatechangelistener Phone Connection Status monitoring, service startup is registered
Notificationiqprovider notifies the message provider, called by the Asmack Library, and receives the message returned by the server (XML)
Notificationpacketlistener notifies the message listener that it is registered after the connection and is called by the Asmack library when Notificationiqprovider receives
After the server message, the listener's callback method Processpacket is called, and the broadcast is sent to Notificationreceiver
Notificationreceiver notifies the broadcast receiver, calls the notification method in Notifier
Notifier calls the Notify method interface notification.
Note: the Parseiq () method in notificationiqprovider resolves the XML data sent by the server and encapsulates it into entities.
Server:
The 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.
Org.androidpn.server.xmpp.auth package inside is a number of certified classes, our own authentication module can be combined here with the ANDROIDPN.
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.
Org.androidpn.server.xmpp.handler package is mainly for the processing of messages, we can define our own handler for different message types, which can be used to process the data sent by the client in the class.
The 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 org.androidpn.server.xmpp.presence contains only the Presencemanager class, which is used to maintain the client's online status.
Org.androidpn.server.xmpp.push There's only one Notificationmanager class that contains an interface to send messages to the client, which encapsulates the data needed to send to clients.
The Org.androidpn.server.xmpp.session package defines a session that represents a persistent link, with each session containing state information for a connection. The user manages all sessions, such as disconnect, delete session and establish connection, add session, etc.
Org.androidpn.server.xmpp.ssl is a toolkit for SSL authentication of connections.
Note: In red package above, Notificationmanager (org.androidpn.server.xmpp.push) with username and message
To the session (Org.androidpn.server.xmpp.session) class, and enclose the corresponding session in XML format, and then call
The Deliver () method in Connection (org.androidpn.server.xmpp.net) sends data to the corresponding user for communication.