本文介绍了如何使用 smack 4.1 将信息查询包发送到 xmpp 服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何向xmpp服务器发送信息查询包,即如何向服务器发送..."来查询一些信息?
how to send info query packet to xmpp server, in other words how to send "..." to server to query some information?
<iq type='set' id='123'>
<push xmlns='p1:push'>
<keepalive max="30"/>
<session duration="60"/>
<body send="all" groupchat="true" from="jid"/>
<status type="xa">Text Message when in push mode</status>
<offline>false</offline>
<notification>
<type>applepush</type>
<id>DeviceToken</id>
</notification>
<appid>application1</appid>
</push>
</iq>
推荐答案
iq 头和命名空间、元素由 smack 自己处理或填充到 xml 中.下面给出了一个xml格式的IQ包及其扩展IQ包的实现.
The iq headers and the namespace,element are handled or filled in the xml by smack itself. A sample IQ packet in xml and its implementation by extending IQ packet are given below.
<iq to='[email protected]' id='khz0k-13678' type='get'><elementName xmlns='http://jabber.org/protocol/muc#something'><item affiliation="member"/></elementName></iq>
public class IQGetSomething extends IQ {
public static final String ELEMENT = "elementName";
public static final String NAMESPACE = "http://jabber.org/protocol/muc#something";
String memberType;
public IQGetSomething() {
super(ELEMENT, NAMESPACE);
setType(Type.get);
}
public String getMemberType() {
return memberType;
}
public void setMemberType(String memberType) {
this.memberType = memberType;
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
xml.append("<item affiliation=\"").escape(memberType).append("\"/>");
return xml;
}
}
这篇关于如何使用 smack 4.1 将信息查询包发送到 xmpp 服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!