【问题标题】:Openfire XMPP component namespace in getChildElement in packet数据包中 getChildElement 中的 Openfire XMPP 组件命名空间
【发布时间】:2016-05-31 11:00:12
【问题描述】:

作为 XMPP 和 Java 的新手(我是 iOS 开发人员),通过遵循一些教程,我设法编写了一个服务器组件 (Openfire) 和客户端 iOS 应用程序(使用 robbiehanson 的 ios xmppframeowrk)。我可以向组件 iOS 客户端发送和接收消息。这是一个抽象代码:

从 iOS 客户端应用发送出席信息到服务器组件:

XMPPPresence *presence = [XMPPPresence presence];
[presence addAttributeWithName:@"to" stringValue:serverComponentJid];
NSXMLElement *someInfo = [NSXMLElement elementWithName:@"someInfo"
                                               stringValue:@"xyz"];
[presence addChild:someInfo];
[_xmppStream sendElement:presence];

在服务器组件中接收数据包:

if (packet instanceof Presence){
        org.xmpp.packet.Presence recvPresence = (Presence) packet;

Element theInfo = recvPresence.getChildElement("someInfo", "***what_shoud_be_the_namespace_here***");
System.out.println("Some info in the presence as " + theInfo.attributeValue("someInfo"));

我可以打印数据包并查看 someInfo。当我在命名空间中传递“”时,我能够正确理解,这是可以理解的。但是我仍然不明白在 xmpp 中使用什么以及如何使用命名空间。请提供任何指南、tut、链接、参考或答案

【问题讨论】:

  • 更新:编辑了问题。如果我发送一个空字符串,那么我可以获得子元素。像元素 theInfo = recvPresence.getChildElement("someInfo", "");。但是我仍然需要一些关于理解 xmpp 命名空间的信息。任何参考..链接等

标签: java ios xmpp openfire xmppframework


【解决方案1】:

命名空间用于定义节(数据包)的“用途/范围”。 它们用于定义功能和绑定操作(解析器、侦听器等),因此任何 API 都可以添加基于 tagName 和命名空间的行为(默认或自定义)。

所以命名空间就像协议的保留键一样使用。

使用自定义命名空间,可以定义自定义 IQ(或其他任何东西),并拥有自定义逻辑/解析器等,以便在您需要时触发 exaclty 并获得您喜欢和需要的 n 个自定义操作。

官方文档:

https://datatracker.ietf.org/doc/rfc6120/?include_text=1

还有更多:

http://xmpp.org/extensions/index.html

【讨论】:

    猜你喜欢
    • 2012-08-08
    • 1970-01-01
    • 2011-07-24
    • 1970-01-01
    • 1970-01-01
    • 2017-09-02
    • 2017-05-28
    • 1970-01-01
    • 2014-03-22
    相关资源
    最近更新 更多