XMPP--XMPP client, server, gateway, and address and message formats

Source: Internet
Author: User

Then the previous article continued to study and summarize.

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. Communicates with the XMPP server via TCP sockets;
    2. Parsing well-organized XML information packets;
    3. Understand the message data type.

As for why the client requirements are so simple, generally speaking, XMPP put the relevant more functional implementation on the server side to implement and processing, which makes the client relatively free. 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):

    1. RFC3920 Core Protocols
    2. RFC3921 Instant Messaging and Presence agreement instant Messaging and presence
    3. XEP-0030 Services Discovery Service Discovery
    4. XEP-0115 Entity capacity entities capabilities
XMPP server

The XMPP server follows two main rules:

    1. Listens for client connections and communicates directly with client applications;
    2. Communicating with other XMPP servers;

Do not underestimate it just follow the principle of less, these two principles is the core of all XMPP server and the root, otherwise, XMPP-based IM at all not to talk about, let alone the modular expansion based on this ...

XMPP open source servers are generally designed to be modular and consist of different code packages (modules/components) that include, but are not limited to, the following:

    1. Session Management
    2. Communication between the user and the server
    3. Communication between servers
    4. DNS (Domain Name System) conversion
    5. Store user's personal information and friends List
    6. Keep information that users receive when they are offline
    7. User Registration
    8. Identity and permission authentication for users
    9. Filter information according to user's requirements
    10. System record

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

    1. RFC3920 Core Protocols
    2. RFC3921 Instant Messaging and Presence agreement instant Messaging and presence
    3. XEP-0030 Services Discovery Service Discovery
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.

From this perspective, the XMPP gateway is XMPP exposes an interface that can be compatible with other mainstream communication protocols (in a sense) based on this, we can implement the corresponding communication protocol to achieve the mutual conversion and communication between XMPP and this protocol, similar to a charger conversion interface, Can be adapted to different types of phones.

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 consists of a series of elements:

    1. Domains (domain identifier);
    2. nodes (node identifier);
    3. Source (resource Identifier).

Its format is [email protected]/resource,[email protected], 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, specify [email protected] Yes, resource can not be specified (optional), but a when logging on to this server, A's jid may be [email protected]/exodus (If a is logged in with Exodus software), or it may 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.

XMPP message Format

3 top-level XML elements are defined in XMPP: Message, Presence, IQ

Message
Used to send information between two Jabber users. The JSM (Jabber Session Manager) is responsible for all messages, regardless of the status of the target user. If the user JSM online immediately, otherwise the JSM will be stored.

To :标识消息的接收方。from : 指发送方的名字或标示(id)oText: 此元素包含了要提交给目标用户的信息

Chestnuts:

<message to= ‘lily@jabber.org/contact’ type =’chat’>    <body> 你好,在忙吗</body></message>

Presence
Used to indicate the user's status, such as online, Away, DND (Do Not disturb), etc. When a 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 is as follows:

<presence>    From =‘lily @ jabber.com/contact’    To = ‘yaoman @ jabber.com/contact‘    <status></status></presence>

The presence element can take several values:
Probe: Used to send a special request to the receiving message party
Subscribe: Automatically sends presence information to the sender when the recipient state changes.

IQ
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, requests the server to get its own buddy list, and the server returns a result inside that is the request.

The main attribute of IQ is type. Including:

    1. Get: Gets the current domain value.
    2. Set: Sets or replaces the value of a get query.
    3. Result: The description succeeded in responding to the previous query.
    4. Error: Errors occurred in query and response.

The structure is as follows:

<iq from =‘lily @ jabber.com/contact’id=’1364564666’ Type=’result’>

One more example:
Presence
Used to determine the state of a user. The message structure is as follows (there will be many other attribute for each XML node, omitted here for the sake of simplicity):

<presence from="[email protected]/contact" to="[email protected]/contact">    <status>online</status></presence>

Message
Used to send a message between two users. Examples of message structures are:

<message from="[email protected]/contact" to="[email protected]/contact" type=“chat”>     <body>hello</body></message>

IQ
Information/request is a request-response mechanism that manages the conversion of two users on an XMPP server, allowing them to query and respond in the appropriate XML format.

<iq from="[email protected]/contact"id=“id11” type=“result”></iq>

The next article continues to learn and summarize my understanding of the issues encountered during the process of reading the XMPP protocol core document RFC3920 core protocol cores.

jessonlv--Lu Guodong original article, reproduced please specify the source: HTTP://BLOG.CSDN.NET/JESSONLV

XMPP--XMPP client, server, gateway, and address and message formats

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.