openfire ping的smack解决方案(维持在线状态)
Posted tiancai
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了openfire ping的smack解决方案(维持在线状态)相关的知识,希望对你有一定的参考价值。
连接中关联如下:
- // iq提供者
- roviderManager.getInstance().addIQProvider("ping", "urn:xmpp:ping",
- new PingIQProvider());
- onnection.addPacketListener(new PacketListener() {
- @Override
- public void processPacket(Packet p) {
- PingIQ pingIQ = (PingIQ) p;
- IQ pongIQ = pingIQ.createResultIQ(pingIQ);
- // 返回
- connection.sendPacket(pongIQ);
- }
- , new PacketTypeFilter(PingIQ.class));
两个关联类,PingIQ,PingIQProvider
- import org.jivesoftware.smack.packet.IQ;
- public class PingIQ extends IQ {
- public static final String ELEMENT = "ping";
- public static final String NAMESPACE = "urn:xmpp:ping";
- @Override
- public String getChildElementXML() {
- StringBuffer sb = new StringBuffer();
- sb.append("<").append(ELEMENT).append(" xmlns="").append(NAMESPACE)
- .append("">");
- sb.append("</").append(ELEMENT).append(">");
- return sb.toString();
- }
- }
- import org.jivesoftware.smack.packet.IQ;
- import org.jivesoftware.smack.provider.IQProvider;
- import org.xmlpull.v1.XmlPullParser;
- public class PingIQProvider implements IQProvider {
- @Override
- public IQ parseIQ(XmlPullParser parser) throws Exception {
- // TODO Auto-generated method stub
- PingIQ iq = new PingIQ();
- return iq;
- }
- }
报文如下:
- <iq xmlns="jabber:client" type="get" id="65dfds" from="localhost" to="[email protected]/test"><ping xmlns="urn:xmpp:ping"/></iq>
- <iq type="result" to="localhost" id="65dfds"/>
http://linyu19872008.iteye.com/blog/1840596
以上是关于openfire ping的smack解决方案(维持在线状态)的主要内容,如果未能解决你的问题,请参考以下文章
Android 聊天是不是有任何 Openfire smack 替代方案?
本地主机上 Smack 和 Openfire 之间的路由错误
Openfire:在android上使用smack向特定人广播消息