android - 在 Ejabberd/XMPP 中禁止用户同时从多个设备登录

标签 android xmpp chat ejabberd smack

Environment:

Ejabberd Version : 16.04

Smack-android-4.1.0

我正在开发一个 Android 聊天应用程序。目前,可以使用相同的用户凭据从多个设备登录。

当前场景如下:

1. User logs in into the app in device A
2. Using the same username and password, the user logs successfully into the app in device B
3. Now device A says, it is disconnected, but continue the chat in device B

但是,根据给定的要求,它的行为应该是这样的:

1. User logs in into the app in device A
2. Using the same username and password, when the user tries to log in from device B, it should not allow it. 
(Since he is already logged in from device A)

很高兴听到您对此的解决方案/想法。提前致谢。

最佳答案

所以我设法使用选项resource_conflict解决了问题

根据Ejabberd Configuring Docs

The option resource_conflict defines the action when a client attempts to login to an account with a resource that is already connected. The option syntax is:

resource_conflict: setresource|closenew|closeold: The possible values match exactly the three possibilities described in XMPP Core: section 7.7.2.2. The default value is closeold. If the client uses old Jabber Non-SASL authentication (XEP-0078), then this option is not respected, and the action performed is closeold.

因此,打开 ejabberd.yml 并将以下行添加到该文件中。

resource_conflict: closenew 

然后重新启动ejabberd服务器。

现在它将禁止新连接客户端的资源绑定(bind)尝试并维持当前连接客户端的 session 。

引用文献:

  1. https://www.rfc-editor.org/rfc/rfc6120#section-7.7.2.2
  2. 阅读 @rubycon 对此的回答 - https://stackoverflow.com/a/51860779/5361779

关于android - 在 Ejabberd/XMPP 中禁止用户同时从多个设备登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51855857/

相关文章:

java - 安卓工作室,javax.net.ssl.SSLHandshakeException : Unacceptable certificate

android - Smack 4.1 SASL 认证错误

ios - 使用 iOS Openfire 和 Robbie Hanson 库以所有者权限加入现有的 XMPP MUC 房间

php - 在后端存储聊天应用程序的聊天消息

python - IOLoop.add_callback vs Tornado 中的 IOLoop.add_timeout?

Android:在另一个位图上绘制多个位图

android - 实时数据 : Remove observer from inside Observer lambda

java - 如何使用 smack Java 获取 IQ 标签?

textarea - 如何在试剂中定义聊天输入字段?

android - FFMpeg 文本动画