繁体   English   中英

数据包中getChildElement中的Openfire XMPP组件名称空间

[英]Openfire XMPP component namespace in getChildElement in packet

通过遵循一些教程,我成为XMPP和Java的新手(我是iOS开发人员),我设法编写了服务器组件(Openfire)和客户端iOS应用程序(使用robbiehanson的ios xmppframeowrk)。 我能够与组件<-> iOS客户端之间收发消息。 这是一个抽象代码:

将状态从iOSclient应用发送到服务器组件:

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,链接,参考或答案

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

因此,名称空间就像协议的保留键一样使用。

使用自定义名称空间,可以定义自定义IQ(或其他任何东西),并具有自定义逻辑/解析器等,以便在需要时进行操作,并根据需要获得n个自定义动作。

官方文档:

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

和更多:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM