xmpp学习要点记录

xmpp

1.message

(1)message 的类型:type="xx"

normal
Messages of type normal are most similar to email messages, since they are single messages to which a response may or may not be forthcoming.

chat
Messages of type chat are exchanged in a real-time “session” between two entities, such as an instant messaging chat between two friends.

groupchat
Messages of type groupchat are exchanged in a multi-user chat room, similar to Internet Relay Chat (we discuss groupchat messages in Chapter 7).

headline
Messages of type headline are used to send alerts and notifications, and a response is not expected at all (a client that receives a headline should not enable a user to reply).

error

If an error occurs in relation to a previously sent message, the entity that detects the problem will return a message of type error.

(2)chat类型的会话状态(选择性的加入)


active:  发出去内容的时候。

compossing:正在输入内容。

paused:正在输入内容,突然中断,并且持续中断了几秒钟。

inactive:短时间不谈话?

gone:结束对话,是指长时间不谈话?


(3)可以使用xhtml来格式化message中body标签的内容,但是前提是客户端要能解析xhtml,否则看不出效果。


2. presence (表示账号的状态信息)

1presence标签的<show/>标签类型:

chat(在线)

Announces that you are available for, and actively seeking, conversation (perhaps you’re feeling especially sociable).

away(短时间离开)

Indicates that you are gone from your IM client, computer, or device for a short period of time; this state is often triggered without human intervention through a feature known as auto-away, commonly found in many IM clients.

xa(长时间离开)
Indicates that you are gone for a longer period of time (xa is shorthand for “eX- tended Away”); your IM client can also automatically generate this state.

dnd(拒绝,请勿打扰)
Announces that you are busy and don’t want to be interrupted right now (dnd is shorthand for “do not disturb”).


2presence标签的<status/>标签类型:对show标签的说明。

<presence>
<show>away</show>
<status>Having a spot of tea</status>

</presence>


3presence标签的<priority/>标签:范围-127-128

用于多设备,比如me@myserver.tld的两台设备office TV,正数表示能收到消息,负数表示不能收到消息。

<presence from="me@myserver.tld/office"> <priority>7</priority>

</presence>

<presence from="me@myserver.tld/TV"> <priority>-1</priority>

</presence>


4)可以用presence来跟陌生人聊天(即不加到自己的通讯录的人)

<message from="alice@wonderland.lit/rabbithole" to="whiterabbit@wonderland.lit"

type="chat">
<body>If you please, sir--</body>

</message>

<presence from="alice@wonderland.lit/rabbithole" to="whiterabbit@wonderland.lit"/>

服务端将返回:

<presence from="whiterabbit@wonderland.lit/mobile" to="alice@wonderland.lit/rabbithole"

type="unavailable"/>


5Rich Presence or extened presence

  • <presence>
  • <status>Pink Floyd - Dogs</status> 
  • </presence> 
  • 如上,可以在presence标签中加一些扩展标签,给好友广播消息,如:我正在收听什么音乐,电影,地理位置信息等。。
  • 注意事项:由于是广播,会比一般的message占用比较大的带宽,所以要慎重考虑数据的大小。
  • 3、vCard(个人名片)
  • including your name, nickname, address, phone and fax number, company affiliation, email address, birthday, a pointer to your website, a photo of you, and even your PGP key
  • 可以通过发送IQ-get来获取vCard
  • <iq from="mouse@wonderland.lit/pool" id="pw91nf84"
  • to="alice@wonderland.lit"
  • type="get">
    <vCard xmlns="vcard-temp"/>
  • </iq>
  • 服务端返回:
  • <iq from="alice@wonderland.lit" id="pw91nf84"
  • to="mouse@wonderland.lit/pool"
  • type="result">
    <vCard xmlns="vcard-temp">
  • <N> <GIVEN>Alice</GIVEN>
  • </N> <URL>http://wonderland.lit/~alice/</URL> <PHOTO>
  • <EXTVAL>http://www.cs.cmu.edu/~rgs/alice03a.gif</EXTVAL> </PHOTO>
  • </vCard> </iq>
  • 可以通过发送IQ-set消息来更新vCard
  • <iq from="alice@wonderland.lit/pda" id="w0s1nd97"
  • to="alice@wonderland.lit"
  • type="set">
    <vCard xmlns="vcard-temp">
  • <N> <GIVEN>Alice</GIVEN>
  • </N> <URL>http://wonderland.lit/~alice/</URL> <PHOTO>
  • <EXTVAL>http://www.cs.cmu.edu/~rgs/alice03a.gif</EXTVAL> </PHOTO>
  • <EMAIL><USERID>alice@wonderland.lit</USERID></EMAIL> </vCard>
  • </iq>
  • 4、过滤和阻止会话
  • 可以通过发送IQ-set消息加上block标签来过滤联系人
  • <iq from="you@yourdomain.tld/newjob" id="yu4er81v"
  • to="you@yourdomain.tld"
  • type="set">
    <block xmlns="urn:xmpp:blocking">
  • <item jid="boss@bigcompany.com"/> </block>
  • </iq>
  • 也可以过滤或阻止整个服务器
  • <iq from="you@yourdomain.tld/newjob" id="i3s91xc3"
  • to="you@yourdomain.tld"
  • type="set">
    <block xmlns="urn:xmpp:blocking">
  • <item jid="spammers.lit"/> </block>
  • </iq>
  • block代表着:
  • 1.对方将看到自己不在线。(服务器不给对方发任何关于当前联系人的prsence)。
  • 2.服务端将不阻止任何对方发来的IQ-get,IQ-set消息并返回<service-unavailable>错误,并且忽略所有的<message/>。
  • 3.自己也不能给对方发送IQ,message,如果发了,则返回<nor-acceptable>错误。
  • (6)blocking的高级设置。
  • <list name="mylist">
    <item type="jid" value="boss@bigcompany.com" action="deny" order="1">
  • <iq/> <message/> <presence-out/>
  • </item>
    <item type="group" value="Work" action="deny" order="2">
  • <presence-in/> </item>
  • <item action="allow" order="3"/> </list>
  • 以上规则的意思是:
  • boss@bigcompany.com发送过来的消息能匹配上第一条规则,但是只过滤IQmessage、以及我自己的对外发送的presence(也就是boss不能看到我在线状态)。
  • 遍历到第二条规则,boss不在这条规则里面,接着往下遍历第三条规则,是allow(不管是什么都allaw),也就是说可以收到boss的presence(能看到boss的在线状态)。
  • 结合这三条规则,整个意思就是:boss不能看到我得在线状态,并且不能给我发任何消息,但是我能看到boss的在线状态。


5. serveice discovery(也叫“disco”)

网络上有各种各样自定义的xmpp协议,可以通过来service discovery来了解这些xmpp协议。有两种方法disco#items和disco#info。

1.首先可以用disco#items来获取某个服务器所包含的节点。

如:client发送,

<iq from="hatter@wonderland.lit/home" id="xl391n47"

to="wonderland.lit"

type="get">
<query xmlns="http://jabber.org/protocol/disco#items"/>

</iq>

server返回:

<iq from="wonderland.lit" id="xl391n47"

to="hatter@wonderland.lit/home"

type="result">
<query xmlns="http://jabber.org/protocol/disco#items">

<item jid="conference.wonderland.lit"/>

<item jid="notify.wonderland.lit"/> </query>

</iq>


2.再通过disco#info来获取某个节点的具体信息。

client发送:

<iq from="hatter@wonderland.lit/home" id="gq02kb71"

to="conference.wonderland.lit"

type="get">
<query xmlns="http://jabber.org/protocol/disco#info"/>

</iq>

server返回:

<iq from="conference.wonderland.lit" id="gq02kb71"

to="hatter@wonderland.lit/home"

type="result">
<query xmlns="http://jabber.org/protocol/disco#info">

<identity category="conference" type="text" name="Chatrooms"/> <feature var="http://jabber.org/protocol/muc"/>
<feature var="jabber:iq:register"/>
<feature var="vcard-temp"/>

</query> </iq>

3.可以重复以上两个步骤来获取到最终用户的信息。(比如一个实体里面有两大聊天室,大聊天室里又包含多个小聊天室,小聊天室里面包含多个用户)


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值