The principle of XMPP protocol

Source: Internet
Author: User
Tags rfc
The XMPP (Extensible Message Processing Field Protocol) is an Extensible Markup Language (XML) protocol that is used for instant messaging (IM) and on-line on-site detection. It facilitates quasi-instant operation between servers. This agreement may eventually allow Internet users to send instant messages to anyone else on the internet, even if their operating system and browsers are different.
In fact, XMPP is a very similar to the HTTP protocol, a data transmission protocol, its process is like "unpack--〉 packaging" process, the user only need to understand the type of it received, and understand the type of return, it can be a good use of XMPP for data communication.

The predecessor of XMPP was Jabber, an open-source form of network Instant Messaging protocol generated by the Organization. XMPP is currently being standardized by IETF International standards Organization. The core results of standardization are divided into two parts;

In the IETF, the IM protocol is divided into four protocols, namely instant messaging and Presence agreements (Instant messaging and Presence Protocol, IMPP), presence and instant messaging protocols (Presence and Instant messaging Protocol, PRIM), Session Initiation protocol for Instant Messaging and Presence Extensions (Sessions initiation Protocol for Instant messaging and Presence leveraging, Simple), and extensible Message Presence Protocol (XMPP). IMPP was originally developed to create a standardized protocol, but today, IMPP has developed into a basic protocol unit that defines the core set of features that all instant messaging protocols should support.
XMPP and simple two protocols are schemas that contribute to the implementation of the specifications described in the IMPP protocol. PRIM was originally a protocol based on instant messaging, similar to XMPP and simple, but no longer used

1. The XMPP agreement is open and developed by the JSF Open source community organization. The XMPP agreement does not belong to any institution or individual, but belongs to the whole community, which guarantees its openness fundamentally.
2. The XMPP protocol has good scalability. In XMPP, instant messaging and presence information are structured information based on XML that is exchanged among 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 so that data is transmitted to the most appropriate resources in a very high efficiency. The application based on XML has good semantic integrity and expansibility.
3. Distributed network architecture. The XMPP protocol is based on the Client/server architecture, but the XMPP protocol itself does not have such limitations. The architecture of the network is very similar to that of e-mail, but it does not incorporate any particular network architecture and is widely applicable.
4. The XMPP has good elasticity. In addition to the applications available for Instant messaging, XMPP can also be used in network management, content feeds, collaborative tools, file sharing, gaming, remote system monitoring, and more.
5. Safety. In Client-to-server Communication and Server-to-server Communication, TLS (transport Layer Security) protocol is used as the encryption method of communication channel to ensure the xmpp of communication. Any XMPP server can be independent of the public XMPP network (for example, in an enterprise intranet), and technologies such as SASL and TLS enhance the security of communications. As shown in the following illustration:





Composition of the XMPP protocol
The main XMPP protocol model and today's widely used XMPP extension:
RFC 3920 XMPP: Core. It defines the network architecture applied in the framework of XMPP protocol, introduces XML stream (XML stream) and XML Stanza (XML section), and prescribes the XML tags that the XMPP protocol uses in the communication process. Using XML tags is fundamentally about the need for protocol openness and extensibility. In addition, in the aspect of communication security, the TLS security transmission mechanism and SASL authentication mechanism are introduced into the kernel, seamless connection with XMPP, which lays the foundation for the security and reliability of the protocol. The Core document also defines the definition and processing of errors, the use of XML specifications, the definition of JID (Jabber identifier,jabber identifiers), naming conventions, and so on. So this is a document that must be supported for all applications based on the XMPP protocol.
RFC 3921: After the user successfully logged on to the server, the post update their own online buddy management, send instant chat messages and other business. All of these operations are done through three basic XML sections: IQ Stanza (IQ section), Presence Stanza (Presence), Message Stanza (Message section). RFC3921 also defines a blocking policy, defined as a variety of blocking methods. It can be said that RFC3921 is the full complement of RFC3920. With the combination of two documents, a basic Instant Messaging protocol platform has been developed to develop a wide variety of applications on this platform.
XEP-0030 Service Search. A powerful protocol for determining the characteristics supported by other entities in the XMPP network.
XEP-0115 entity performance. XEP-0030 's one-time customization can change the function of alternating advertising.
XEP-0045 Chat with many people. A set of protocols that define the participation and management of multi-user chat rooms, similar to the relay Chat of the Internet, are highly secure.
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 are not durable enough to maintain TCP connections to the server.
XEP-0166 jingle. The whole structure of multimedia communication negotiation is stipulated.
XEP-0167 jingle Audio Content Description Format. Defines the speech transfer process from one XMPP entity to another.
XEP-0176 jingle ICE (Interactive connectivity Establishment) transport. The ice transmission mechanism, which solves the problem of how to make a connection between a firewall or an entity under the protection of NAT (network address translation).
XEP-0177 jingle Raw UDP Transport. A pure UDP transport mechanism that describes how to establish a connection without a firewall and under the same network.
XEP-0180 Jingle video Content Description Format. The video transfer process from one XMPP entity to another is defined.
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, rather than using Peer-to-peer client-side architectures like most instant messaging software, this means that in most cases, when two clients communicate, their messages are passed through the server (with the exception, for example, when transferring files to two clients). This architecture is mainly designed to simplify the client, putting most of the work on the server side, so that the client's work is simpler, and when the functionality is added, most of it is done on the server side. The frame structure of the XMPP service is shown in the following illustration. There are three roles defined in XMPP, XMPP client, XMPP server, gateway. Communication can take place between any two of these three. The server simultaneously undertakes the client information record, the connection management and the information routing function. The gateway undertakes the interconnection with the heterogeneous instant communication system, the heterogeneous system may include the SMS (short message), the MSN, the ICQ and so on. The basic network form is that a single client connects to a single-server via TCP/IP and then transmits XML on top of it, working on the following principles:
(1) The node connects to the server, (2) The server uses the certificate of the local directory system to authenticate it, (3) The node specifies the target address, the server tells the target State, (4) The server locates, connects and authenticates each other, (5) the nodes interact.

XMPP Client
A design standard for a XMPP system is that it must support a simple client. In fact, the XMPP system architecture has few limitations on the client. The features that a XMPP client must support are:
1. Communication with XMPP server via TCP sockets;
2. Parse the organized XML information packet;
3. Understand message data types.
XMPP transfers complexity from the client to the server side. This makes it easy for the client to write, and also easier to update the system functionality. The XMPP client communicates with the server via XML on the 5222 port of the TCP socket without the need for direct communication between the clients.
The basic XMPP client must implement the following standard protocols (XEP-0211):
RFC3920 Core Protocol
RFC3921 Instant Messaging and presence protocol Instant messaging and Presence
XEP-0030 Services Discovery Service Discovery
XEP-0115 entity capability entity capabilities


XMPP server


The XMPP server follows two main rules:
L Monitor client connections and communicate directly with client applications;
L Communicate with other XMPP servers;
XMPP open source servers are generally designed to be modular and consist of different code packs that handle session management, communication between users and servers, communication between servers, DNS (Domain Name System) conversion, storage of user personal information and friends lists, The user is kept in the offline information received, user registration, user identity and authority certification, according to user requirements filter information and system records. In addition, the server can extend through additional services, such as a complete security policy, allowing the server component's connection or client selection to gateway to other messaging systems.
The basic XMPP server must implement the following standard protocols
RFC3920 Core Protocol
RFC3921 Instant Messaging and presence protocol Instant messaging and Presence
XEP-0030 Services Discovery Service Discovery


XMPP Gateway


The salient feature of XMPP is the exchange of information and user online status with other instant messaging systems. Due to the different protocols, XMPP and other systems exchange information must be implemented through the conversion of the Protocol, the current several mainstream instant communication protocols are not exposed, so the XMPP server itself does not implement and other protocol conversion, but its architecture allows conversion of the implementation. The server that implements this particular function is called Gateway in the XMPP architecture. At present, XMPP has implemented the protocol conversion with AIM, ICQ, IRC, MSN massager, RSS0.9 and Yahoo Massager. Because of the presence of gateways, the XMPP architecture is in fact compatible with all other instant messaging networks, which undoubtedly greatly improves the flexibility and scalability of the XMPP.


XMPP address format
An entity, called a contact in the XMPP network structure, has a unique identifier Jabber identifier (JID), an entity address that represents a Jabber user, but can also represent other content, such as a chat room. An effective Jid includes a series of elements: (1) domain name (domains identifier), (2) node (nodes identifier), (3) source (resource identifier). Its format is node@domain/resource,node@domain, similar to e-mail address format. Domain used to indicate the point of different devices or locations, this is optional, such as a on the Server1 registered a user, the user name is Doom, then a Jid is Doom@serverl, when sending messages, indicate doom@serverl on it, Resource can be specified without specifying, but a while logging into this server, FL jid may be doom@serverl, Exodus (if a is logged in with Exodus software), or doom@serverl/psi (if a is logged in with the PSI software). A resource is used only to identify a location or device belonging to a user, and a user can connect to the same XMPP server with multiple resources at the same time.


The XMPP message format XMPP defines 3 top-level XML elements: messages, Presence, and IQ, which are described below for the three elements.


<Message>
Used to send information between two Jabber users. JSM (Jabber Session Manager) is responsible for all messages, regardless of the status of the target user. If the user submits the online JSM immediately, otherwise the JSM is stored.
To: Identifies the recipient of the message.
From: Refers to the sender's name or mark (ID) o
Text: This element contains the information to be submitted to the target user.
The structure looks like this:


<message to= ' lily@jabber.org/contact ' type = ' chat ' >
<body> Hello, are you busy </body>
</message>


<Presence>
Used to indicate the user's status, such as: online, Away, DND (do not Disturb) and so on. When the user goes offline or changes his or her state, a presence element is inserted in the context of the stream to indicate its state. The structure looks like this:
<presence>
from = ' Lily @ jabber.com/contact '
to = ' Yaoman @ jabber.com/contact '
<status> Online </status>
</presence>
The <presence> element can take the following several values:
Probe: Used to send special requests to the Accept message method
Subscribe: Automatically sends presence information to the sender when the receiver state changes.

< IQ >
A request/response mechanism from which a request is sent from one entity and another entity receives the request and responds. For example, the client inserts an element into the context of the stream, requests a list of friends from the server, and the server returns one, which is the result of the request.
<iq > The Primary property is type. Including:
Get: Gets the current domain value.
Set: Sets or replaces the value of a get query.
Result: Indicates a successful response to a previous query.
Error: Errors that occur in queries and responses.
The structure looks like this:
<iq from = ' Lily @ jabber.com/contact ' id= ' 1364564666 ' type= ' result ' >

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.