XMPP Core Protocol Client

Source: Internet
Author: User
XMPP is the official name of the jabber protocol. Its core protocol is a specification for sending XML via socket and other media. Very simple and easy to implement.

First, establish a network connection through socket

Then the client sends an XML start tag such as <stream: stream...> to the server.

Then the server returns a tag such as <stream: stream...> As a handshake signal.

Then, it indicates that the two sides can begin to interwork the XML stream.

Disconnection does not seem to need to be sent </stream: stream>, but it is not necessarily necessary. You need to read the protocol in detail. Currently, it is no big problem to directly disconnect the socket connection.

<IQ id = 'abc'>... </IQ> when an XML section (XML stanza) is sent, the server uses <IQ id = 'abc'>... </IQ>. Currently, the XML section stipulated in the Core Protocol has three presence, IQ, and message.

Looking at the overall protocol communication process, a complete XML file is sent over a segment. <stream> is the root node, then, each time the root node under the root node is sent.

So currently, using Delphi requires three classes:

Txmppclient (inherited from tidtcpcustom)

Txmpplistenerthread (inherited from tidthread, because this thread is better than VCL. Special listening threads are required because XMPP does not have a clear answer format like HTTP. XML stanza such as message may arrive at any time. Therefore, a special listening thread is required to constantly read from the system's socket stack)

Txmppprotocol (this is used to implement network communication logic that expresses the instant messaging logic based on core protocols, such as sending messages and going online. As the receiver of txmppclient events)

Currently, the core of the implementation is txmppclient, which requires four basic functions. Connect (after the connection, it automatically sends the <stream start tag and can determine whether the handshake is successful ), send stanza (send an XML section), stanza received (call all registered callback functions when an XML section is received), and disconnect (disconnect, clean and secure ). Even the four simple functions require synchronization and cooperation between the client and the listening thread, which is not too simple and tasteless. If you have implemented all these operations tomorrow night, you can start to work on the top-level agreement.

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.