基于smack的xmpp packet 重写
基于Smack 实现Notification数据包。smack的类中有一个org.jivesoftware.smack.packet.IQ只需对他重写即可,在做的时候其实可以简单一点的,如果你使用tinder.jar 包,其IQ org.xmpp.packet.IQ 有一个 setChildElement 方法与 getChildElement相对应,但smack没有!
主要用于与android Client之间Push通信。定义一套自己的数据包格式:
<iq id="11111" to="aa@qq.com" type="get">
<notification xmlns="androidpn:iq:notification">
<id>123456</id>
<apiKey>1234567890</apiKey>
<title>nothing</title>
<message>jintiantianqibuycuo</message>
<uri>heoo</uri>
</notification>
</iq>
重新写了一下body的部分,代码如下:
/**
* Notification 重写XMPP 的IQ packet (Smack)
*
* @author Charles
* @date 2011/10/16
*
*
*/ package com.gareatech.testxmpp; import org.jivesoftware.smack.packet.IQ; /**
* 重构之后的数据样式
* -
* <iq id="11111" to="aa@qq.com" type="get">
* <notification xmlns="androidpn:iq:notification">
* <id>123456</id>
* <apiKey>1234567890</apiKey>
* <title>nothing</title>
* <message>jintiantianqibuycuo</message>
* <uri>heoo</uri>
* </notification>
* </iq>
*
* */
public class Notification extends IQ {
private Notify notify; public Notify getNotify() {
return notify;
} public void setNotify(Notify notify) {
this.notify = notify;
} @Override
public String getChildElementXML() {
StringBuilder buf = new StringBuilder();
if (notify != null) {
buf.append(notify.toXML());
}
return buf.toString();
} /**
* Notify
* Body 部分,重写为<>
*
* */
public static class Notify {
private String id;
private String apiKey ;
private String title;
private String message;
private String uri; public String getId() {
return id;
} public void setId(String id) {
this.id = id;
} public String getApiKey() {
return apiKey;
} public void setApiKey(String apiKey) {
this.apiKey = apiKey;
} public String getTitle() {
return title;
} public void setTitle(String title) {
this.title = title;
} public String getMessage() {
return message;
} public void setMessage(String message) {
this.message = message;
} public String getUri() {
return uri;
} public void setUri(String uri) {
this.uri = uri;
} public String toXML() {
StringBuilder buf = new StringBuilder();
buf.append("<notification xmlns=\"").append("androidpn:iq:notification\">");
buf.append("<id>").append(id).append("</id>");
buf.append("<apiKey>").append(apiKey).append("</apiKey>");
buf.append("<title>").append(title).append("</title>");
buf.append("<message>").append(message).append("</message>");
buf.append("<uri>").append(uri).append("</uri>");
buf.append("</notification>");
return buf.toString();
}
}
}
基于smack的xmpp packet 重写的更多相关文章
- XMPP即时通讯协议使用(二)——基于Smack相关操作
package com.test; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator ...
- Android studio使用smack连接xmpp服务器收发消息
我使用的是ejabberd16.09的Linux版本,安装教程网上有很多,我在这里只介绍一下Android端连接.登录和收发消息的方法.文章最后附上了我写的一个demo,欢迎大家参考. ejabber ...
- 基于xmpp openfire smack开发之openfire介绍和部署[1]
前言 http://blog.csdn.net/shimiso/article/details/8816558 Java领域的即时通信的解决方案可以考虑openfire+spark+smack.当然也 ...
- Openfire XMPP Smack RTC IM 即时通讯 聊天 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- 基于openfire+smack即时通讯instant message开发
前言 Java领域的即时通信的解决方案可以考虑openfire+spark+smack.当然也有其他的选择. Openfire 是基于Jabber协议(XMPP)实现的即时通信服务器端版本,目前建议使 ...
- xmpp openfire smack 介绍和openfire安装及使用
前言 Java领域的即时通信的解决方案可以考虑openfire+spark+smack.当然也有其他的选择. Openfire是基于Jabber协议(XMPP)实现的即时通信服务器端版本,目前建议使用 ...
- 基于XMPP协议的Android即时通信系
以前做过一个基于XMPP协议的聊天社交软件,总结了一下.发出来. 设计基于开源的XMPP即时通信协议,采用C/S体系结构,通过GPRS无线网络用TCP协议连接到服务器,以架设开源的Openfn'e服务 ...
- (转)基于即时通信和LBS技术的位置感知服务(二):XMPP协议总结以及开源解决方案
在<基于即时通信和LBS技术的位置感知服务(一):提出问题及解决方案>一文中,提到尝试使用XMPP协议来实现即时通信.本文将对XMPP协议框架以及相关的C/S架构进行介绍,协议的底层实现不 ...
- 基于XMPP 协议的开发 android
设计过一款基于开源的XMPP即时通信协议的软件.採用C/S协议,通过GPRS无线网络用TCP协议到server.以架设开源的Openfire server作为即时通讯平台 系统主要由下面部分组成:一是 ...
随机推荐
- http://www.linuxidc.com/Linux/2015-02/114265.htm
http://www.linuxidc.com/Linux/2015-02/114265.htm
- ZOJ - 3195 Design the city
题目要对每次询问将一个树形图的三个点连接,输出最短距离. 利用tarjan离线算法,算出每次询问的任意两个点的最短公共祖先,并在dfs过程中求出离根的距离.把每次询问的三个点两两求出最短距离,这样最终 ...
- spin_lock & mutex_lock的区别?
http://blog.csdn.net/sunnytina/article/details/7615520 为什么需要内核锁? 多核处理器下,会存在多个进程处于内核态的情况,而在内核态下,进程是 ...
- lib-flexible 结合 WKWebView 的样式错乱解决方法
技术栈 lib-flexible 是淘宝的可伸缩方案 WKWebView 是ios8以上支持的网页控件 问题场景 最新公司一个项目使用 lib-flexible 来做移动端的伸缩解决方案,页面在saf ...
- android:process为耗资源操作指定一个新进程
当有一些耗费内存比较多的操作时,可以通过android:process指定一个新的进程.保证程序运行. 例如: 一个后台长期运行的service: <service android:name=& ...
- tlplayer,wzplayer所有平台通用加密测试视频
此视频文件为通用版本,支持tlplayer,wzplayer,能在ios,android,windows,mac等平台上使用,发布此文件紧为方便用户测试. 下载地址:http://www.coolra ...
- Ubuntu 出现apt-get: Package has no installation candidate问题
今天在安装软件的时候出现了Package has no installation candidate的问题,如: # apt-get install <packagename> Read ...
- rebuild过程
/** The class defining a handle to an Innodb table */ class ha_innobase: public handler { row_prebui ...
- 【转】Ubuntu安装基础教程
原文网址:http://teliute.org/linux/Ubsetup/lesson23/lesson23.html 二十三.安装Ubuntu14.04 返回目录 下一课 14.04 版安装与前面 ...
- 处理MVC中默认的Json方法返回时间的问题
利用 Json方法返回 数据时,如果有时间格式,会变成 "\/Date(1369419656217)\/" 这个样子,问了同事找到个解决方法 using Newtonsoft.Js ...