XMPP (Scalable Message Processing site protocol) is based on the Extensible Markup Language (XML) protocol, which is used for instant messaging (IM) and online field probing. It promotes quasi-real-time operations between servers. This protocol may eventually allow Internet users to send instant messages to others on the Internet, even if their operating systems are different from those in browsers.
The predecessor of XMPP is jabber, an open-source network instant communication protocol. XMPP has been standardized by IETF International Standards Organization. The core results of standardization are divided into two parts;
In IETF, the IM protocol is divided into four types: instant message and attendance protocol (IMPP) session Initiation Protocol for instant messaging and presence leveraging extensions, simple), and scalable message attendance protocol (XMPP ). IMPP was initially developed to create a standardized protocol, but today IMPP has become a basic Protocol Unit, defining the core feature set that all Instant Messaging Protocols should support.
The XMPP and simple protocols are architectures that help implement the specifications described in the IMPP protocol. Prim was initially based on the instant messaging protocol, similar to XMPP and simple, but it is no longer used
1. the XMPP protocol is open and developed by the JSF open-source community. XMPP does not belong to any institution or individual, but to the whole community, which fundamentally guarantees its openness.
2. the XMPP protocol has good scalability. In XMPP, both instant messages and on-site information are structured information based on XML, Which is exchanged between communication entities in the form of XML stanza. XMPP plays a role in the common transmission layer of XML structured data. It embeds attendance and context sensitive information into XML structured data, in this way, data is delivered to the most appropriate resources with high efficiency. Applications built based on XML have good semantic integrity and scalability.
3. Distributed Network Architecture. The XMPP protocol is based on the client/server architecture, but the XMPP protocol does not have such restrictions. The network architecture is very similar to email, but it is not applicable to any specific network architecture.
4. XMPP is very flexible. In addition to instant messaging applications, XMPP can also be used in network management, content feed, collaboration tools, file sharing, gaming, remote system monitoring, and so on.
5. Security. In client-to-server communication, XMPP uses the Transport Layer Security (TLS) protocol as the encryption method for communication channels to ensure communication security. No matter what xmppserver can be independent from the public XMPP network (for example, in an enterprise's internal network), the use of SASL and TLS Technologies Enhance communication security. As shown in the following figure:
Composition of XMPP protocol
Basic XMPP protocol templates and XMPP extensions that are widely used today:
RFC 3920 XMPP: core. Defines the network architecture of applications under the XMPP protocol framework, introduces XML Stream (XML Stream) and XML stanza (XML section), and specifies the XML tag used in the communication process of XMPP. The use of XML tags is basically the need for protocol openness and scalability. In addition, in terms of communication security, the TLS Secure Transmission Mechanism and SASL authentication mechanism are introduced into the kernel to seamlessly connect with XMPP, laying the foundation for the security and reliability of the Protocol. The core document also specifies the definition and processing of errors, the XML usage specification, the definition of jid (jabber identifier, Jabber identifier), and the naming convention. Therefore, this document must be supported by all XMPP-based applications.
RFC 3921: After logging on to the server, you can publish and update your online friend management and instant chat messages. All of these businesses are completed through three major XML sections: IQ stanza (IQ Section), presence stanza (presence Section), and message stanza (message section ). Rfc3921 also defines blocking policies as multiple blocking methods. It can be said that rfc3921 is a supplement to rfc3920. The two documents are combined to form a major instant messaging protocol platform, on which various applications can be developed.
XEP-0030 service search. A powerful protocol used to determine the features supported by other entities in the XMPP network.
XEP-0115 entity performance. One of the XEP-0030's ability to change alternating ad functionality in real time through instant attendance customization.
XEP-0045 multiplayer chat. A set of protocols that define tokens and manage multi-user chat rooms, similar to relay chat on the Internet, have high security.
XEP-0096 file transfer. Defines the transfer from an XMPP object to another file.
XEP-0124 HTTP binding. Binding XMPP to HTTP instead of TCP is mainly used for devices that cannot maintain persistent connections with servertcp.
XEP-0166 jingle. Specifies the overall architecture of multimedia communication negotiation.
XEP-0167 jingle audio content description format. Defines the process from an XMPP object to another voice transmission process.
XEP-0176 jingle ice (Interactive connectivity establishment) transport. ICE transmission mechanism, the file solves the problem of how to set up a connection to an object protected by the firewall or NAT (network address translation.
XEP-0177 jingle raw UDP Transport. The file describes how to establish a connection in the same network without a firewall.
XEP-0180 jingle video content description format. Defines a video transmission process from an XMPP object to another.
XEP-0181 jingle DTMF (Dual Tone Multi-frequency ).
XEP-0183 jingle telepathy transport method.
XMPP protocol network architecture
XMPP is a typical C/S architecture, instead of using p2pclient to client architecture like most instant messaging software. That is to say, when two clients communicate in most cases, their messages are all transmitted through the server (there are also exceptions, such as when two clients transmit files ). the principal architecture is to simplify the client and put most of the work on the server. In this way, the client is easier to work on than the worker, and when a function is added, mostly on the server side. the Framework Structure of the XMPP service is as follows. XMPP defines three roles: xmppclient, xmppserver, and gateway. communication can take place between the two randomly. the server is responsible for recording client information, connection management, and routing of information at the same time. gateways are interconnected with heterogeneous instant messaging systems. heterogeneous systems can include SMS, MSN, and ICQ. the main network mode is that a single client connects to a single server through TCP/IP, and then transmits XML on it. The working principle is:
(1) connect the node to the server; (2) use the certificate in the local Folder system to authenticate it; (3) Specify the target address for the node to notify the server of the Target status; (4) server searches, connects, and authenticates each other. (5) nodes interact with each other.
Xmppclient
An XMPP system design standard must support simple clients. In fact, the XMPP system architecture imposes few restrictions on the client. An XMPP client must support the following functions:
1. Communicate with XMPP server through TCP socket;
2. parse the organized XML Information Package;
3. Understand the message data type.
XMPP transfers complexity from client to server. This makes it easy to write the client and update the system functions. The XMPP client and the server communicate with each other through XML in the 5222 port of the TCP socket, and do not need to communicate directly between the client.
The main XMPP client must implement the following standard protocol (XEP-0211 ):
Rfc3920 Core Protocol Core
Rfc3921 instant messaging and attendance agreement instant messaging and presence
XEP-0030 Service Discovery
XEP-0115 entity capability entity capabilities
Xmppserver
XMPP server follows two main rules:
L listen to the client connection and directly communicate with the client application;
L communication with other XMPP servers;
XMPP open-source server is generally designed to be modular and consists of different code packages, these code packages handle session management, communications between users and servers, communications between servers, DNS (Domain Name System) convert and store the user's personal information and friends list, retain the information received by the user when the user goes offline, user injection, user identity and permission authentication, and filter information and system records according to the user's requirements. In addition, the server can be extended by attaching services, such as the complete security policy, agreeing to the connection or client selection of the server component to the gateway of other message systems.
The main XMPP server must implement the following standard protocols:
Rfc3920 Core Protocol Core
Rfc3921 instant messaging and attendance agreement instant messaging and presence
XEP-0030 Service Discovery
XMPP Gateway
XMPP is characterized by the ability to exchange information with other instant messaging systems and users' online conditions. Because the protocols are different, XMPP and other systems must exchange information through protocol conversion. Currently, no mainstream Instant Messaging Protocols are available, therefore, XMPP server itself does not implement conversion from other protocols, but its architecture agrees to the implementation of conversion. The server that implements this special function is called a gateway in the XMPP architecture ). Currently, XMPP implements protocol conversion with aim, ICQ, IRC, MSN massager, rss0.9, and Yahoo massager. Because of the existence of gateways, the XMPP architecture is actually compatible with all other instant communication networks, which undoubtedly greatly improves the flexibility and scalability of XMPP.
XMPP address format
An object is called a contact in the XMPP network structure. It has a unique identifier jabber identifier (jid), that is, the entity address, used to represent a jabber user, but it can also represent other content, such as a chat room. A valid jid contains a series of elements: (1) domain identifier; (2) node identifier; (3) Source (resource identifier ). the format is [email protected]/resource, [email protected], similar to the address format of the email. domain is used to indicate the contacts of different devices or locations. This is optional. For example, if a attaches a user to server1 and username is doom, the jid of A is [email protected]. when sending a message, you can specify [email protected]. resource does not need to be specified. However, when a logs on to this server The IDS may be [email protected] and exodus (assuming a is logged on with the Exodus software), or [email protected]/PSI (assuming a is logged on with the Psi software ). A resource is only used to identify a user's location or device. A user can connect multiple resources to the same XMPP server at the same time.
XMPP Message format
XMPP defines three top-level XML elements: Message, presence, and IQ. The three elements are described below.
<Message>
Send messages between two jabber users. The JSM (jabber Session Manager) is responsible for meeting all the messages, regardless of the target user's status. Assume that the user submits the JSM online immediately; otherwise, the JSM is stored.
To: identifies the message receiver.
From: The sender's name or identifier (ID) O
Text: This element contains the information to be submitted to the target user.
The structure is shown as follows:
<Message to = '[email protected]/contact' type = 'chat'>
<Body> Hello, are you busy? </body>
</Message>
<Presence>
Used to indicate the user's status, such as online, away, and DND. When a user is offline or changing his/her State, a presence element is inserted in the stream context to indicate his/her State. The structure is shown as follows:
<Presence>
From = 'lily @ jabber.com/contact'
To = 'yaoman @ jabber.com/contact'
<Status> online </status>
</Presence>
The <presence> element can take the following values:
Probe: used to send special requests to receive message Methods
Subscribe: when the status of the receiver changes, the receiver actively sends the presence information to the sender.
<IQ>
A request/response mechanism is used to send a request from an entity, while another entity accepts the request and responds to the request. for example, the client inserts an element in the stream context to request the server to obtain its friends list. The server returns a result of the request.
<IQ> the basic attribute is type. Includes:
Get: Get the current domain value.
Set: set or replace the get query value.
Result: The query is successful.
Error: errors in queries and responses.
The structure is shown as follows:
<IQ from = 'lily @ jabber.com/contact'id='1364564666' type = 'result'>
Principles of XMPP protocol