【问题标题】:Chat process in XMPP Openfire server using Android application使用 Android 应用程序在 XMPP Openfire 服务器中的聊天过程
【发布时间】:2015-09-22 05:57:28
【问题描述】:

我将 Openfire XMPP 服务器用于 Android 聊天应用程序。我可以使用我的应用程序连接并登录到服务器。

现在我想知道如何在这个聊天应用程序中发送好友请求和接受好友请求。

我可以从服务器获取所有用户,但我想知道开始聊天的过程。

提前致谢。

【问题讨论】:

  • 我假设您正在使用 Smack 作为您的 android 应用程序的 xmpp sdk?
  • 是的 android 端的 api @Mark
  • Android ADD FRIEND using Smack 的可能重复项

标签: xmpp openfire smack


【解决方案1】:

添加/接受好友请求的过程比看起来要复杂一些,您需要处理presenceroster iq 节的一些杂耍。

我将尝试使用下面的联系人操作向您说明发送/接收哪些节。

1. Add contact
    To add a contact you need to send a `subscribe` stanza. 
    <presence xmlns="jabber:client" to="you@app.com/123" id="9VO8j-1" type="subscribe" from="me@app.com/1234" />
    1.1. Request accepted
        When adding a contact and the other app "accepts the request" you receive two stanzas:
            1. <presence xmlns="jabber:client" from="you@app.com/123" id="9VO8j-1" type="subscribed" to="me@app.com/1234" />
            2. <presence xmlns="jabber:client" from="you@app.com/123" id="9VO8j-2" type="subscribe" to="me@app.com/1234" />
            3. <presence xmlns="jabber:client" from="me@app.com/1234" id="9VO8j-3" type="subscribed" to="you@app.com/123" />

    1.2. Request Denied
        When the request is denied you receive an "UNSUBSCRIBED" stanza.
            Example: <presence xmlns="jabber:client" from="you@app.com/123" id="9VO8j-1" type="unsubscribed" to="me@app.com/1234" />

2. Accept contact request
    1. <presence xmlns="jabber:client" from="me@app.com/1234" id="9VO8j-1" type="subscribed" to="you@app.com/123" />
    2. <presence xmlns="jabber:client" from="me@app.com/1234" id="9VO8j-2" type="subscribe" to="you@app.com/123" />

3. Deny contact request
    <presence xmlns="jabber:client" from="me@app.com/1234" id="9VO8j-1" type="unsubscribed" to="you@app.com/123" />

4. Remove contact
    When you "Delete" a contact you should be in fact be "deleting" it locally in your app and from the roster. 
    This is done by sending two stanzas:
        1. <presence xmlns="jabber:client" from="me@app.com/1234" id="9VO8j-3" type="unsubscribe" to="you@app.com/123"/>
        2. <iq from='me@app.com/1234' id='ah382g67' to='you@app.com/123' type='set'>
             <query xmlns='jabber:iq:roster' ver='ver34'>
               <item jid='you@app.com/123' subscription='remove'/>
             </query>
            </iq>

注意: 上述用例不包括与presence 节。每当联系人更改 subscriptionask 类型时,服务器会自动发送这些信息。

为了更好地了解这些工作流程的详细工作原理,我建议您阅读最新的 RFC(由您的服务器实现)。您可以在office site 上找到它。

参见第 3 节。管理名册

【讨论】:

  • 忘了说。这是一个通用的答案,您可以轻松地将其调整为 smack 并发送/处理所需的节。
猜你喜欢
  • 1970-01-01
  • 2012-02-12
  • 1970-01-01
  • 2016-08-02
  • 2014-06-19
  • 2016-04-03
  • 1970-01-01
  • 2023-01-28
  • 1970-01-01
相关资源
最近更新 更多