XMPP Protocol Learning Notes

Source: Internet
Author: User

This document is a learning note based on the XMPP protocol video tutorial.

Each client uses Jid (jabber identifier) as the identity, in the format [user "@"]domain["/" resource], where

Domain: Server domain name; User: Username; resource: the location or device belonging to the user, such as a mobile phone or a computer
A user can connect to a unified XMPP server at the same time with a variety of resources, complete Jid example: [Email protected]/iphone6s
Common properties of Stanza: From,to,type,id (from property and to property following Jid format)
From: Identifies the sender of the message, but considering the presence of a forged client message source, the server generally does not directly use from the data to confirm who sent the data, but more connected state to do the verification.
To: Specifies the object to be sent by the message, and if the to property is not given, the server considers the message to be sent to itself and is not forwarded to the other user.
Type: Specify a section of stanza
The unique identity of the Id:stanza, when the client sends a message to the server, the server responds to the client, where the ID is used to indicate whether the server is a unique identifier for the client that previously sent the message to the server. The customer will add the ID to the message when it sends a message to the server. The server adds the same ID to the message when replying to the client.

Stream Label
The client requests a connection by sending the following section of stanza to the server (note that there is no end tag)

<    to= "example.com"    xmlns= "Jabber:client"     Xmlns:stream= "Http://etherx.jabber.org/streams"    version= "1.0"  >

When the server receives a message from the customer service side, the connection is established by replying to the following section of stanza (no end tag)

<    from= "example.com"    to= "ClientId"    xmlns  = "Jabber:client"    xmlns:stream= "Http://etherx.jabber.org/streams"     version= "1.0">

The above ID has a server-side random generation, and then as the client and service-side connection of the unique ID, after the interaction, the client and the server to establish a successful connection before the client and server is considered to support the XMPP protocol for further data communication. Note that the stanza not sent between the client and the server has only a start tag and no end tag, meaning that it is always connected, and if you want to disconnect, just send the end tag to the other party </stream:stream>.


The presence tag is used to identify the current user online status, the basic structure is as follows

< Presence    from= "[e-mail protected]"   to= "[email protected]"   type = "Unavailable" />

The above XML tag means [email protected] tells [email protected] He has been offline,presence the type of the optional parameters available (online), unavailable ( offline),

Subscribe (can subscribe), subscribed (authorized subscription), unsubscribe (unsubscribe), unsubscribed (cancelled), error (send error). When the client is online, you can enrich the online status with some extended tags, such as:

< Presence >   < Show >away</show>   <status> Dining out </status></presence

The show label indicates a more detailed online status, indicating a temporary departure, and status is the most further explanation.

The show label has the following optional parameters: Chat (online and willing and chat with others), away (not in a short time), XA (long time Off), DND (Do Not Disturb).


The message label is used to transfer specific content in the following format:

< message       from = "[email protected]"      to= "[email protected]"     type= "chat">      <body> weekend go to the big health care roar do not roar ah! </ Body > </ message >

the optional parameters for the type attribute in message are:Normal (Independent message. Does not belong to any one session), chat (indicates a one-to-two session, two-person session), Groupchat (group chat, equivalent to QQ Group or discussion group concept), headline (headline), Error (Errors)

The IQ (information Query) tag structure is as follows:

 <  iq  from  = "[email protected]"   ID  = "Idididi"   to  = "[email protected]"   type  = "Get"    >  <  query  xmlns  = "Jabber:iq:roster"  />  </ iq  >  

Where from and to is specified in the same jid.query tag roster refers to the meaning of the contact list. Type optional values are: Get (get data, similar to get request in HTTP protocol), set (set data, similar to post request in HTTP protocol), result (for corresponding data), error (Errors occurred)

The above IQ stanza indicates that the user [email protected] initiated a request to the server to query his or her contact, and the results of its response might be as follows:

<IQ from= "[email protected]"ID= "Idididi" to= "[email protected]"type= "Result">    <Queryxmlns= "Jabber:iq:roster">        <ItemJid= "[email protected]"/>        <ItemJid= "[email protected]"/>        <ItemJid= "[email protected]"/>         <ItemJid= "[email protected]"/>   </Query></IQ>

Note the ID in the IQ tag must be consistent when sending a GET request and returning result. IQ tags are not only used for query requests, but also for user registration, login, notification, etc.

The complete stanza is as follows

<!--a complete XML stanza -<Stream:stream><!--stream is used to establish the initialization of the connection -<Presence><!--presence tags are used to identify the current user state -<Show/></Presence><message to= "Foo" ><body/></message><IQ to= "Bar"><Query/></IQ>...</Stream:stream>

XMPP Protocol Learning Notes

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.