1 Why Choose
XMPP
Protocol
In the IETF, the IM protocol is divided into four protocols, namely instant information and Presence Protocol (Instant Messaging and Presence Protocol, IMPP), presence and Instant Messaging Protocol (presence and Instant Messaging Protocol, PRIM), Session Initiation protocol for Instant Messaging and Presence Extensions (Session Initiation Protocol for Instant Messaging and Presence leveraging Extensions, Simple), as well as extensible Message Presence Protocol (XMPP)
The XMPP protocol is the predecessor of Jabber, we take the XMPP protocol master to implement IM mainly considering that the XMPP protocol is based on XML, which inherits the flexible development in XML environment. This indicates that XMPP is extensible, so XMPP information can be not only simple text, but can carry complex data and files of various formats
1. The XMPP protocol is open and developed by the JSF Open source community organization. The XMPP protocol is not owned by any institution or individual, but belongs to the entire community, which fundamentally guarantees its openness.
2. The XMPP protocol has good extensibility. In XMPP, both instant messages and presence information are XML-based structured information exchanged between communication entities in the form of an XML section (XML Stanza). XMPP plays the role of the universal Transport layer of XML structured data, which embeds presence and context-sensitive information into XML structured data, allowing the data to be delivered to the most appropriate resource with great efficiency. The application based on XML has good semantic integrity and extensibility.
3. Distributed network architecture. The XMPP protocol is based on the Client/server architecture, but the XMPP protocol itself has no such limitations. The architecture of the network is very similar to e-mail, but it is not combined with any particular network architecture and is widely applicable.
4. XMPP has good elasticity. In addition to the applications available for Instant messaging, XMPP can be used in network management, content feeds, collaboration tools, file sharing, gaming, remote system monitoring, and more.
5. Security. XMPP uses the TLS (Transport Layer Security) protocol as the communication channel encryption method in Client-to-server communication, and server-to-server communication to ensure the security of communication. Any XMPP server can be independent of the public XMPP network (for example, within an intranet), and the use of technologies such as SASL and TLS enhances communication security. As shown in the following:
2 basic network structure of XMPP
XMPP is a typical C/s architecture, not like most instant messaging software, which uses peer-to-client architecture, which means that in most cases, when two clients are communicating, their messages are delivered through the server (with exceptions, such as when transferring files to two clients). With this architecture, the main purpose is to simplify the client, the majority of the work on the server side, so that the client's work is relatively simple, and when the increase in functionality, most of the server-side. The framework structure of the XMPP service is as shown. Three roles are defined in XMPP, XMPP client, XMPP server, gateway. Communication can occur bidirectional between any two of these three. The server also assumes the client information record, connection management and information routing function. The gateway undertakes the interconnection with the heterogeneous instant communication system, and the heterogeneous system can include SMS (SMS), MSN, ICQ and so on. The basic network form is that a single client connects to a single server over TCP/IP and then transfers the XML over it, which works by:
(1) The node is connected to the server, (2) the server authenticates with the certificate on the local Directory system, (3) The node specifies the target address, the server informs the target State, (4) The server finds, connects and authenticates each other, and (5) interacts with the nodes.
2.1 XMPP Client
One design standard for XMPP systems is the need to support simple clients. In fact, the XMPP system architecture has only a few limitations on clients. The features that an XMPP client must support are:
1. Communicate with the XMPP server via TCP sockets;
2. Parse well-organized XML packets;
3. Understand the message data type.
XMPP transfers complexity from the client to the server side. This makes it very easy for clients to write, and it is also easier to update system functionality. The XMPP client communicates with the server through XML on port 5222 of the TCP socket without requiring direct communication between the clients.
The basic XMPP client must implement the following standard protocol (XEP-0211):
RFC3920 Core Protocols
RFC3921 Instant Messaging and Presence agreement instant Messaging and presence
XEP-0030 Services Discovery Service Discovery
XEP-0115 Entity capacity entities capabilities
2.2 XMPP Server
The XMPP server follows two main rules:
L Monitor client connections and communicate directly with client applications;
L Communication with other XMPP servers;
XMPP open source servers are generally designed to be modular and consist of different code packages that handle session management, communication between users and servers, communication between servers, DNS (Domain Name System) transformations, storing user's personal information and friends list, Keep the information that the user receives at the downline, the user registers, the user's identity and authority authentication, filter the information and the system record according to the user's request. In addition, servers can be extended through additional services, such as full security policies, allowing connection of server components or client selection, gateways to other messaging systems.
The basic XMPP server must implement the following standard protocols
RFC3920 Core Protocols
RFC3921 Instant Messaging and Presence agreement instant Messaging and presence
XEP-0030 Services Discovery Service Discovery
2.3 XMPP Gateway
XMPP is characterized by the ability to exchange information and user online conditions with other instant messaging systems. Because of the different protocols, XMPP and other system exchange information must be implemented through the conversion of the Protocol, there are currently several mainstream instant communication protocols are not disclosed, so the XMPP server itself does not implement and other protocol conversion, but its architecture allows the implementation of the transformation. The server that implements this particular feature is called the Gateway in the XMPP architecture. Currently, XMPP implements protocol conversions with AIM, ICQ, IRC, MSN massager, RSS0.9, and Yahoo Massager. Because of the presence of gateways, the XMPP architecture is virtually compatible with all other instant communication networks, which undoubtedly greatly improves the flexibility and scalability of XMPP.
3 server-side introduction
3.1 What is
OpenFire
OpenFire is developed in Java, and the open source real-time collaboration (RTC) server is based on the XMPP (Jabber) protocol. You can use it to easily build an efficient Instant Messaging server.
OpenFire is easy to install and use, and is managed with the Web. A single server can support tens of thousands of concurrent users.
Because of the open XMPP protocol, you can use various IM client software that supports the XMPP protocol to log on to the service.
3.2 Why use
OpenFire
A, OpenFire for Java Open Source project
B. Using an open XMPP protocol
C, there are a variety of non-system version
D. Using socket communication
E, a single server can support tens of thousands of concurrent users, build a distributed cloud server can easily provide a large number of concurrent users.
F, Socket long connection
G, server stability
H, provide the interface, can develop their own plug-in
4 composition of the XMPP protocol
RFC 3920 XMPP: Core. Defines the network architecture applied under the XMPP protocol framework, introduces the XML stream (XML flow) and XML Stanza (XML section), and specifies the XML tags that the XMPP protocol uses in the communication process. The use of XML tags is fundamentally the need for openness and extensibility of protocols. In addition, in the security aspect of communication, the TLS secure transmission mechanism and the SASL authentication mechanism are introduced into the kernel, and the connection with XMPP is seamless, which lays the foundation for the security and reliability of the protocol. The Core document also specifies the definition and handling of errors, the use of XML, the definition of JID (Jabber identifier,jabber identifiers), naming conventions, and so on. So this is a document that must be supported by all XMPP protocol-based applications.
RFC 3921: After users successfully log on to the server, publish updates their online friend management, send instant chat messages and other businesses. All of these businesses are done through three basic XML sections: IQ Stanza (IQ section), Presence Stanza (presence), Message Stanza (Message section). RFC3921 also defines blocking policies, which are defined as multiple blocking methods. It can be said that RFC3921 is the full complement of RFC3920. Together, two documents form a basic Instant Messaging protocol platform that can be used to develop a wide variety of applications.
XEP-0030 Service Search. A powerful protocol for determining the features supported by other entities in the XMPP network.
XEP-0115 solid performance. One of XEP-0030 's customizable, instant-on-the-fly, can change the ad function in real time.
XEP-0045 Chat with many people. A set of protocols that define the participation and management of multi-user chat rooms, similar to the Internet Relay Chat, with high security.
XEP-0096 file transfer. Defines a file transfer from one XMPP entity to another.
XEP-0124 HTTP bindings. Bind XMPP to HTTP instead of TCP, primarily for devices that do not persist with server TCP connections.
XEP-0166 jingle. The whole structure of multimedia communication negotiation is stipulated.
XEP-0167 jingle Audio Content Description Format. Defines the voice transfer process from one XMPP entity to another.
XEP-0176 jingle ICE (Interactive Connectivity Establishment) Transport. Ice transport mechanism, which resolves the issue of how to make a connection to an entity that is protected by a firewall or NAT (Network Address translation).
XEP-0177 jingle Raw UDP Transport. A pure UDP transport mechanism that describes how to establish a connection under the same network without a firewall.
XEP-0180 jingle Video Content Description Format. Defines the video transfer process from one XMPP entity to another.
XEP-0181 jingle DTMF (Dual Tone multi-frequency).
XEP-0183 jingle Telepathy Transport Method.
5 XMPP address format
An entity is called a contact in the XMPP network structure, it has a unique identifier Jabber identifier (JID), which is the entity address, which is used to represent a jabber user, but can also represent other content, such as a chat room. A valid Jid includes a series of elements: (1) domain name (domains identifier), (2) node (nodes identifier), and (3) source (resource identifier). Its format is [email protected]/resource,node@domain, similar to the email address format. Domain is used to indicate a different device or location, this is optional, for example a in Server1 registered a user, the user name is Doom, then a jid is [email protected], when sending a message, indicate [ Email protected] OK, resource can not be specified, but a when logging in to this server, FL jid may be [email protected], Exodus ( If a is logged in with Exodus software, it may also be [email protected]/PSI (if a is logged in with PSI software). Resources are used only to identify the location or device belonging to the user, and a user can connect to the same XMPP server with multiple resources at the same time.
6 XMPP Message Format
There are 3 types of XMPP communication primitives: message, Presence, and IQ.
6.1 Message
Message is a basic push message method that does not require a response. Mainly used in applications such as IM, groupchat, alert, and notification.
The main attributes are as follows:
The 6.1.1 Type property , which has 5 main types:
Normal: Similar to email, the main feature is not to request a response;
Chat: Similar to QQ friends live chat, the main feature is real-time communication;
Groupchat: Similar to group chat in chat room;
Headline: For sending alert and notification;
Error: If a message error is sent, the entity that found the fault will use this category to notify the sender of an error;
6.1.2 to property : Identifies the recipient of the message.
6.1.3 from property : Refers to the sender's name or label. To prevent an address from leaking, this address is usually filled out by the sender's server, not the sender.
load (payload): e.g. Body,subject,thread
Example:
<message
to= "[Email protected]/contact]
Type= "Chat" >
<body> Hello, are you busy </body>
</message>
6.2 Presence
Presenceused to indicate the state of a user, such as:Online,away,DND (Do Not Disturb)and so on. When you change your state, you will beStreamthe context in which you insert aPresenceelement to indicate its state. If you want to acceptPresencethe message must go through a callPresence Subscriptionthe authorization process.
6.2.1 Properties :
6.2.1.1 Type property, not required. There are the following categories
Subscribe: Subscribing to another user's status
Probe: Request for additional user status
Unavailable: Not available, offline (offline) status
6.2.1.2 to property: Identifies the recipient of the message.
6.2.1.3 from property: Refers to the sender's name or label.
6.2.2 load ( Payload ):
6.2.2.1 Show:
6.2.2.2 Status: Free-form, readable text. Also called rich presence or extended presence, commonly used to indicate the user's current mood, activity, listening to the song, watching the video, where the chat room, visit the page, play games and so on.
6.2.2.3 Priority: Range -128~127. High-priority resource can accept messages sent to bare Jid, and low-priority resource cannot. A resource with a negative priority cannot receive a message sent to bare Jid.
Example:
<presence from= "[Email PROTECTED]/PDA" >
<show>xa</show>
<status>down the Rabbit hole!</status>
</presence>
6.3 IQ (Info/query)
A request/response mechanism from an entity that sends a request, another entity accepts the request, and responds. For example, the client inserts an element into the context of the stream, asks the server for its friend list, and the server returns one, which is the result of the request.
The primary attribute is type. Including:
Get: Gets the current domain value. Similar to the HTTP GET method.
Set: Sets or replaces the value of a get query. Similar to the HTTP put method.
Result: The description succeeded in responding to the previous query. Similar to HTTP status code 200.
Error: Errors occurred in query and response.
Example:
<iq from= "[Email PROTECTED]/PDA]
Id= "Rr82a1z7"
to= "[Email protected]"
Type= "Get" >
<query xmlns= "Jabber:iq:roster"/>
</iq>
XMPP 3920 The most reliable Chinese translation document
Http://wenku.baidu.com/view/563b1ebff121dd36a32d8225.html
xmpp-rfc3921 Chinese
Http://wenku.baidu.com/view/37ac3efafab069dc502201c7.html
Simple Introduction to XMPP protocol