- 浏览: 571292 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (253)
- java (84)
- python (22)
- 设计模式 (12)
- 数据结构和算法 (7)
- ibatis (1)
- 数据挖掘 (2)
- 集体智慧读书笔记 (1)
- ubuntu (4)
- lucene (11)
- 算法 第4版 (11)
- apache mina (16)
- memcached (1)
- android (9)
- netty (6)
- mongodb (2)
- maven (2)
- openfire (2)
- 服务端 (21)
- 产品 (0)
- apache (1)
- 选择 (2)
- 构架WEB高性能站点 (7)
- redis (8)
- 诗词歌赋 (3)
- 源代码阅读 (5)
- 前端 (1)
- javascript (3)
- guice (1)
- 分布式 (5)
- 总结-2014 (4)
- jvm (1)
最新评论
-
liu_jiaqiang:
写的挺好
maven多项目管理 -
H972900846:
我想知道哪里整的,如果是自己写的,那有点牛呀如果是抄的请说明出 ...
SSL身份认证原理 -
春天好:
博主写的很好,赞一个,多谢分享 *(^-^*)分享一个免费好用 ...
定向网站爬虫---初级例子 -
fenglingabc:
经过测试,parameterType="java.u ...
mybatis获取主键和存储过程返回值 -
jyghqpkl:
[u][/u] ...
Cookie的secure 属性
1.5.4 IQ 节 <iq>节表示的是Info/Query(信息与查询),它为XMPP通信提供请求与响应机制。它与HTTP 协议的基本工作原理非常相似,允许获取和设置查询,与HTTP 的GET 和POST 动作类似。 每个<iq>节都必须有一个响应,而且前面曾经提到过,该节的必需的id 属性将用来把响应 与导致该响应的请求关联起来。<iq>节有四种,通过该节的type 属性区分。有两种<iq>节请求 (get 和set)和两种响应(result 和error)。在本书中,这些节通常被缩写为IQ-get、IQ-set、IQ-result 和IQ-error。 每一个IQ-get 或IQ-set 节均必须接收响应的IQ-result 或IQ-error 节。下面的示例给出了一 些常见的<iq>节以及它们可能的响应。注意,与<message>和<presence>节(它们定义了子元素) 不同,<iq>节通常只包含与它们功能相关的扩展元素。此外,每一对<iq>节必须匹配id 属性。 <iq from='jane@longbourn.lit/garden' type='get' id='roster1'> <query xmlns='jabber:iq:roster'/> </iq> <iq to='jane@longbourn.lit/garden' type='error' id='roster1'> <query xmlns='jabber:iq:roster'/> <error type='cancel'> <feature-not-implemented xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/> </error> </iq> Jane 向她的服务器发送了一个格式错误的花名册请求。服务器使用一个错误提示节作为响 应。后面我们将详细讨论错误提示节。 <iq from='jane@longbourn.lit/garden' type='get' id='roster2'> <query xmlns='jabber:iq:roster'/> </iq> <iq to='jane@longbourn.lit/garden' type='result' id='roster2'> <query xmlns='jabber:iq:roster'> <item jid='elizabeth@longbourn.lit' name='Elizabeth'/> <item jid='bingley@netherfield.lit' name='Bingley'/> </query> </iq> 在重新发送正确的请求之后,服务器将Jane 的简短花名册响应给她。可以看到Elizabeth 和 Bingley 均在Jane 的联系人列表中。 第1 章了解 XMPP 协议 15 <iq from='jane@longbourn.lit/garden' type='set' id='roster3'> <query xmlns='jabber:iq:roster'> <item jid='darcy@pemberley.lit' name='Mr. Darcy'/> </query> </iq> <iq to='jane@longbourn.lit/garden' type='result' id='roster3'/> Jane 试图将Darcy 添加到自己的花名册中,服务器用一个空白IQ-result 节来指出添加成功。 如果应答节只是成功确认,那么IQ-result 节通常是空白的。 在任何需要结果数据或者需要简单确认的场合中,<iq>节都非常有用。大多数XMPP 扩展 协议混合使用<iq>和<message>节来实现它们的功能。<iq>节用于类似于配置和状态变化这样的 信息,而<message>节则用于常规通信。在某些场合中,<iq>节也用于通信,这是因为节确认机 制可实现限速功能。
NotificationManager类中的IQ创建方法
/** * Creates a new notification IQ and returns it. */ private IQ createNotificationIQ(String apiKey, String title, String message, String uri) { Random random = new Random(); String id = Integer.toHexString(random.nextInt()); // String id = String.valueOf(System.currentTimeMillis()); Element notification = DocumentHelper.createElement(QName.get( "notification", NOTIFICATION_NAMESPACE)); notification.addElement("id").setText(id); notification.addElement("apiKey").setText(apiKey); notification.addElement("title").setText(title); notification.addElement("message").setText(message); notification.addElement("uri").setText(uri); IQ iq = new IQ(); iq.setType(IQ.Type.set); iq.setChildElement(notification); return iq; }
tinder-1.2.1.jar包中的 IQ类中的方法
public void setChildElement(Element childElement) { for (Iterator i = this.element.elementIterator(); i.hasNext(); ) { this.element.remove((Element)i.next()); } this.element.add(childElement); }
public IQ() { this.element = docFactory.createDocument().addElement("iq"); String id = String.valueOf(random.nextInt(1000) + "-" + sequence++); setType(Type.get); setID(id); }
/** * Broadcasts a newly created notification message to all connected users. * * @param apiKey the API key * @param title the title * @param message the message details * @param uri the uri */ public void sendBroadcast(String apiKey, String title, String message, String uri) { log.debug("sendBroadcast()..."); IQ notificationIQ = createNotificationIQ(apiKey, title, message, uri); for (ClientSession session : sessionManager.getSessions()) { if (session.getPresence().isAvailable()) { notificationIQ.setTo(session.getAddress()); session.deliver(notificationIQ); } } }
IQ是继承Packet其中
@NotThreadSafe public abstract class Packet { private static final Logger Log = LoggerFactory.getLogger(Packet.class); protected static final DocumentFactory docFactory = DocumentFactory.getInstance(); protected Element element; protected JID toJID; protected JID fromJID;
public void setTo(JID to) { this.toJID = to; if (to == null) { this.element.addAttribute("to", null); } else this.element.addAttribute("to", to.toString()); }
可以看出JID就是要广播的地址 ,xmpp协议中的地址。
Connection类中的 使用Apache mina管理
public void deliver(Packet packet) { log.debug("SENT: " + packet.toXML()); if (!isClosed()) { IoBuffer buffer = IoBuffer.allocate(4096); buffer.setAutoExpand(true); boolean errorDelivering = false; try { XMLWriter xmlSerializer = new XMLWriter(new IoBufferWriter( buffer, (CharsetEncoder) encoder.get()), new OutputFormat()); xmlSerializer.write(packet.getElement()); xmlSerializer.flush(); buffer.flip(); ioSession.write(buffer); } catch (Exception e) { log.debug("Connection: Error delivering packet" + "\n" + this.toString(), e); errorDelivering = true; } if (errorDelivering) { close(); } else { session.incrementServerPacketCount(); } } }
发表评论
-
protobuf-dt插件
2015-03-24 13:16 1368protobuf-dt: 安装前先安装xtext 可 ... -
java循环标签
2015-03-20 16:13 560今天看 源码的时候 看到 一个小语法 参考: ... -
java程序性能优化 --阅读
2014-10-14 17:56 669闲着,真实无聊; 发现一本好书《java程序性能优 ... -
jetty invalid entry CRC问题
2014-08-04 11:42 15281: http://stackoverflow.com/qu ... -
guice注入
2014-05-24 12:13 9397Google Guice3.0: http://code. ... -
eclipse快捷键
2014-05-21 16:01 5321: clrl+alt+r : 最常用,快速定位到文件 2 ... -
java clone
2014-05-16 17:04 489转:http://www.blogjava.net/ora ... -
ThreadLocal
2014-05-13 18:39 730简单介绍一下ThreadLocal的原理:1.Thread ... -
hession
2014-04-30 12:33 656一、首先先说Hessian是什么? Hessian:he ... -
冒泡和快速排序java
2014-04-19 18:01 7141: 冒泡最简单一种: /** * 算法效率o ... -
java生产者和消费者模型三种实现
2014-04-19 17:51 13341: 生产者和消费者的问题,生产者生产产品到缓冲区,消费者 ... -
单例模式
2014-03-14 16:06 711今天看到群里,关于单例模式的多线程下的安全问题: 1:最 ... -
freemarker的使用
2014-02-28 16:42 7971:freemarker eclipse插件安装方法:ht ... -
java 引用类型和内存泄露
2013-11-21 17:48 553http://blog.csdn.net/luoshenfu ... -
java泛型
2013-11-07 13:52 401Class<T>在实例化的时候,T要替换成具体 ... -
filter执行顺序
2013-10-12 11:16 1097多个筛选器的运行顺序取决于下列规则: 将 filt ... -
spring rmi远程调用
2013-09-09 11:48 11441:以前用jmi发布服务,实现分布式的一种方式,远程调用, ... -
spring mvc返回204状态码
2013-07-24 09:27 38781:204是没内容 不跳转的 代表请求成功的意思 ... -
editplus去掉多余空行
2013-07-19 21:05 6951: ^[ \t]*\n 用正则表达式替换 -
spring3 aop 使用详细
2013-06-06 11:10 01:目标:拦截所有的@Controller中的方法 ...
相关推荐
agsXMPP\XMPP协议--即时通讯工具实现原理
xmpp-over-websocket 的目标是提供一个实时信息基于 xmpp 和 websocket pull 或者 poll 的解决方案。 Getting Started Clone git 库的子模块,运行通讯脚本,然后每个子模块会生成一个发布包。 步骤:1) 部署发布包...
hipchat (xmpp) - 一个golang包用于与HipChat通信通过XMPP
JMeterPlugins-XMPP-1.4.0
XMPP协议分析,xmpp是即时通讯IM中比较普遍的应用
对XMPP协议进行介绍,了解XMPP协议标准RFC 3920。
XMPP的核心功能定义在Extensible Messaging and Presence Protocol (XMPP): Core [XMPP-CORE|XMPP文档列表/XMPP正式RFC标准/RFC3920]. 这些功能 -- 主要是 XML流, 使用 TLS和SASL,以及流的根元素之下的, , 和 <iq/> ...
标签:activemq-xmpp-5.6.0-sources.jar,activemq,xmpp,5.6.0,sources,jar包下载,依赖包
gloox1.07 beta c++ 最新版xmpp协议源码
xmpp-hybrid-app-examples-源码.rar
Android-XMPP-openfire-实现IM
标签:activemq-xmpp-4.1.2.jar,activemq,xmpp,4.1.2,jar包下载,依赖包
java本地可用,连接、登陆、接收消息
XMPP-3921 doc XMPP-3921 doc XMPP-3921 doc XMPP-3921 doc
XMPP4R-Hipchat 这是一个使用 XMPP4R 库的 HipChat / Slack XMPP 适配器。 安装 将此行添加到应用程序的 Gemfile 中: gem 'xmpp4r-hipchat' 然后执行: $ bundle 或者自己安装: $ gem install xmpp4r-...
标签:activemq-xmpp-5.4.2-sources.jar,activemq,xmpp,5.4.2,sources,jar包下载,依赖包
标签:activemq-xmpp-5.4.1-sources.jar,activemq,xmpp,5.4.1,sources,jar包下载,依赖包
标签:activemq-xmpp-5.3.0-sources.jar,activemq,xmpp,5.3.0,sources,jar包下载,依赖包