how to use smack 4.1 for how to send info query packet to xmpp server?

萝らか妹 提交于 2019-12-31 03:36:28

问题


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>

回答1:


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='jid@domain.in' 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;
}
}


来源:https://stackoverflow.com/questions/41630978/how-to-use-smack-4-1-for-how-to-send-info-query-packet-to-xmpp-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!