基于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作为即时通讯平台 系统主要由下面部分组成:一是 ...
随机推荐
- loadrunner throughput(吞吐量)理解
转自http://www.51testing.com/html/29/n-110129.html Throughput翻译为吞吐量,按照常规理解网络吞吐量表示在单位时间内通过网卡数据量之和,其中即 ...
- mysql select count(filed) 问题(where条件没有数据匹配的话也有数据返回)。
问题: SELECT count(*),user_id FROM tb_rp_logintrace WHERE id=-1 返回结果: count(*), user_id 0 ...
- python 检测文件编码等
参考:http://my.oschina.net/waterbear/blog/149852 chardet模块,能够实现文本编码的检查, 核心代码: import chardet chardet.d ...
- Nagios "process_cgivars()" 单字节溢出漏洞
漏洞版本: Nagios Nagios 4.x Nagios Nagios 3.x 漏洞描述: Nagios是一款免费开放源代码的主机和服务监视软件,可使用在多种Linux和Unix操作系统下. Na ...
- 第K顺序统计量
1.第K顺序统计量概念 在一个由n个元素组成的集合中,第k个顺序统计量是该集合中第k小的元素.例如,最小值是第1顺序统计量,最大值是第n顺序统计量. 2.求Top K元素与求第K顺序统计量不同 Top ...
- POJ1456 Supermarket 贪心
贪心策略:一定先卖价值最大的,然后考虑卖当前的物品,卖的日期越靠后,越优,可以为以后的物品提供机会 #include <stdio.h> #include <string.h> ...
- Problem - 433C - Codeforces解题报告
对于这题本人刚开始的时候的想法是:先把最大两数差的位置找到然后merge计算一个值再与一连串相同的数做merge后计算一个值比较取最大值输出:可提交后发现不对,于是本人就搜了一下正解发现原来这题的正确 ...
- VS2013 单元测试(使用VS2013自带的单元测试)
本文是官方文档的学习笔记,官方文档在这里. 1.打开VS3013,随便建一个解决方案,比如叫:LearnUnitTest,建一个类库项目LearnUnitTest_Bank,该项目中添加一个BankA ...
- 【CSS】Intermediate7:Pseudo Elements
1.selector:pseudo element{property:value;} 2.first-letter first-line CSS3:: 与pseudo class 区别 old br ...
- Java笔记(十九)……多线程
概述 进程: 是一个正在执行中的程序 每一个进程执行都有一个执行顺序,该执行顺序是一个执行路径,或者叫一个控制单元 线程: 就是进程中的一个独立的控制单元,线程在控制着进程的执行 一个进程中至少有一个 ...