将 API 添加到 xmpp 服务器?不清楚带有自定义API的xmpp服务器的概念
我正在开发一个可以通过 iPhone 和 Android 上的本机应用程序访问的聊天应用程序。我花了一些时间研究如何完成它,但我仍然没有很好地掌握它。例如,我在这里看到并遵循了有关移动 tuts 的教程(http://mobile.tutsplus.com/tutorials/iphone/building-a-jabber-client-for-ios-server-setup/)
但是,让我们说我希望我的聊天应用程序能够超越登录/检查和登录功能。发送消息,我该怎么做?
例如,我想添加的一项功能是能够在用户库中搜索以下条件:
- 现在在线的用户
- 满足特定条件(位置、年龄等)的用户
例如,如果我使用 ejabberd 或 Openfire 作为我的 xmpp 服务器,如何添加这些可从 iPhone/Android 访问的新自定义 API?
我只是在这里做一个粗略的例子,但也许能够做这样的事情会很好:
-(NSArray*) findUsersInCity:(NSString *)cityName
我怎样才能让 xmpp 服务器将我传回符合城市名称标准的用户列表?
先感谢您!!
I'm doing a chat application accessible via native apps on the iPhone and Android. I've spent some time researching how it would be done, but I sill don't have quite a good grasp of it yet. For example, I've seen and followed the tutorial on mobile tuts here (http://mobile.tutsplus.com/tutorials/iphone/building-a-jabber-client-for-ios-server-setup/)
However, let's say that I want my chat apps to be able to go beyond the login/check & send messages, how would I do that?
For example, one feature I would like to add is to be able to search the userbase for criteria such as:
- users online now
- users who meet certain critera (location, age, etc)
If, for example, I am using ejabberd or Openfire as my xmpp server, how do I add these new custom APIs that would be accessible from iPhone/Android?
I'm just making a rough example here, but maybe it would be nice to be able to do something like this:
-(NSArray*) findUsersInCity:(NSString *)cityName
How would I be able to make the xmpp server pass me back a list of those users who match the cityname criteria?
Thank you in advance!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几种不同的方法可以扩展 XMPP 服务器:
XMPP 组件
组件独立于 XMPP 服务器而存在。您可以用几乎任何语言编写它们,并且它们按照协议连接到 XMPP 服务器 (http:// /xmpp.org/extensions/xep-0114.html)。组件注册以处理服务器的子域,并且发送到该组件的任何消息/IQ 都会直接从 XMPP 服务器传递到您的代码,供您处理和响应。例如,邮件可以发送至
[电子邮件受保护] /resource
而不是[电子邮件受保护]/资源
。组件的好处是它应该与任何 XMPP 服务器一起使用(无论如何都支持组件,这是大多数主要组件)。例如,如果您从 Openfire 更改为 ejabberd,您不需要做任何工作。缺点是它们无法访问服务器本身内的数据。如果您想提供对外部数据(例如您自己的数据库)的访问,那么很好,但可能还不够。
插件/模块
这些是特定于服务器的,并且必须使用与服务器相同的语言编写。 Openfire 有插件,ejabberd 有模块。它们可以与 XMPP 服务器集成,并为您提供更多选择。然而,切换 XMPP 服务器需要从头开始开发。如果你想为 Openfire 制作一个插件,请查看 插件指南和 Openfire API:API 文档。 API 非常广泛,您可以获得服务器可用的大部分数据。
修改源代码
这不是一个好的选择,但可能值得一提 - 您可以下载 Openfire 的源代码,进行修改并重新构建它。仅当您确定 API 无法满足您的需求时,我才会这样做。
There are several different ways to extend an XMPP server:
XMPP Component
Components exist separately to the XMPP server. You can write them in pretty much any language and they connect to the XMPP server following a protocol (http://xmpp.org/extensions/xep-0114.html). A component registers to handle a subdomain of a server and any messages/IQ's addressed to that component are passed straight from the XMPP server to your code, for you to process and respond. For instance, a message could be addressed to
[email protected]/resource
instead of[email protected]/resource
.The benefit of a Component is that it should work with any XMPP server (that supports components anyway, which are most of the main ones). Should you change from Openfire to ejabberd for instance, you shouldn't have to do any work. The downside is that they can't access data within the server itself. Fine if you want to provide access to external data (say your own database) but might not be sufficient.
Plugin/Module
These are server-specific and must be written in the same language as the server. Openfire has plugins, ejabberd has modules. These can integrate with the XMPP server and give you far more options. Switching XMPP servers would require starting development from scratch however. If you want to make a plugin for Openfire, have a look at the Plugin Guide and the Openfire API: API Docs. The API is extensive and you can get at most of the data available to the server.
Modify Source Code
Not a good option but possibly worth mentioning - you could download the source code for Openfire, make your modifications and re-build it. I would only do this if you were certain the API can't give you what you need.