Communication Data Stream of Asmack Development Series, asmack Development Data Stream

Source: Internet
Author: User
Tags http 200

Communication Data Stream of Asmack Development Series, asmack Development Data Stream

In the previous section, we introduced the basics of XMPP. Before that, we talked about the flood of communication, and then it was over. Next, let's talk about this section. It is mainly "stanzas" (Section). In the previous section, we say that to distinguish stanzas, we need to distinguish it from its name, attribute TYPE, and subnode. This section describes Message, Presence, Information Query (IQ), and Extensibility ).

1. A Message <message/> is a typical Push method in xmpp. It does not need to be replied and is a post-reading mechanism. Suitable for IM, Groupchat, alert, and Notification. According to its type attribute, it can be divided into: 1) Regular (normal) Regular messages are especially like mail messages, because the messages you send to others can be returned or not returned by others. 2) chat messages are real-time conversations between two entities. For example, you and your qq friends are chatting. 3) GroupChat is used in multi-user conversation rooms. 4) Headline headlines are used to send warnings and notifications. Such messages do not need to be replied.
5) an Error message is generally a response to a message, telling the other party what is wrong.
Message has the Type attribute, and there are other attributes: 1) where to go, that is, who to talk to (JID); 2) from. In fact, when you send a message to someone else, the from field is not filled by you, but by your server. Why? In fact, if you fill in the space, you are obviously James, and you fill in the space of James, isn't it a Spoofing. Right. 3) id. This message is unique. It is particularly useful during debugging, and the Message can also have load, that is, subnodes. For example, <body/> and <subject/> are used in one-to-one conversations. Here is an example:
<message from="madhatter@wonderland.lit/foo"to="alice@wonderland.lit"type="chat"><body>Who are you?</body><subject>Query</subject></message>

2. Presence is one of the different characteristics of real-time communication and other applications. What Will attendance accomplish? In fact, your QQ friends are online, and then your QQ list will light up their pictures. This process is: first, you subscribe to the attendance messages of others, that is, people are your friends and subscribed by default, of course, he can reject your subscription (offline ). Therefore, Presence is a "Publish-subscribe" publishing-subscription mode. An example of a Presence message is as follows:
<presence from="alice@wonderland.lit/pda"><show>xa</show><status>down the rabbit hole!</status></presence>
3. Information Query (IQ) Info/Query (IQ) provides a Request-Response mechanism, which is a bit like GET, POST, PUT method. Unlike <message/>, an IQ package can have only one load, that is, only one subnode. In addition, the IQ package must receive a response for a request, which may come from the other party or the other party's server (this is easy to understand, because when the other party is not reachable ). The Id of the IQ package is very important. When you request an IQ package that contains an id, the id is still used as the id of the package, this indicates the response to your request. The type attribute of the IQ package includes: 1) get (request ). This type of request is to request information from the other party, similar to http get. 2) set ). This is similar to http post or PUT. 3) result ). The result of the get request, or the set response (similar to the HTTP 200 Status Code ). 4) error ). When the other party cannot meet your needs, it will return an error to you, or its server will return an error to you.
An IQ package for querying the roster:
<iq from="alice@wonderland.lit/pda" id="rr82a1z7"to="alice@wonderland.lit" type="get"><query xmlns="jabber:iq:roster"/></iq>
Reply:
<iq from="alice@wonderland.lit" id="rr82a1z7"to="alice@wonderland.lit/pda" type="result"><query xmlns="jabber:iq:roster"><item jid="whiterabbit@wonderland.lit"/><item jid="lory@wonderland.lit"/><item jid="mouse@wonderland.lit"/><item jid="sister@realworld.lit"/></query></iq>

Add a member to the Roster:
<iq from="alice@wonderland.lit/pda"id="ru761vd7"to="alice@wonderland.lit" type="set"><query xmlns="jabber:iq:roster"><item jid="madhatter@wonderland.lit"/></query></iq>

Reply:
<iq from="alice@wonderland.lit" id="ru761vd7"to="alice@wonderland.lit/pda" type="result"/>

The interaction process with the server is shown in Figure 4. Because the scalability is based on XML, the scalability is very good. I will not talk about it here.
5. In the future, I will release the source code analysis for source code parsing. I will try my best to look forward to it. My colleague will be playing CS. 88.












Full-duplex communication supports data streams

Full Duplex: send and receive data at the same time.
For example, the mobile phone is full duplex. Call a ticket. The walkie talkie is called Half Duplex. Only one user can talk about it after he finishes talking about it.
Any communication method that data streams can use.
It can only be said that the question is not good. I can only answer this question.

For data streams in Socket communication

1. When the client writes EOF, the server stops the endless loop when it determines the EOF.
2. The client first sends the number of bytes of a file, and then exits after the server obtains the required number of bytes.

The 2nd methods are commonly used.

Related Article

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.