最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]swift中XMPP连接出错:

XMPP crifan 3255浏览 0评论

折腾:

[已解决]swift XMPP调试:没有执行到didReceivePresence和 didReceiveMessage
期间,代码:
    func xmppStream(sender: XMPPStream!, didNotAuthenticate error: DDXMLElement!)
    {
        print("didNotAuthenticate")
        print("error=\(error)") //error=<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>
    }
遇到错误:
<failure xmlns=”urn:ietf:params:xml:ns:xmpp-sasl”><not-authorized/></failure>
搜:
<failure xmlns=”urn:ietf:params:xml:ns:xmpp-sasl”><not-authorized/></failure>
参考:
去openfire服务器看看:
check openfire server settings
服务器属性
服务器启动时间:    1 天, 6 小时, 9 分钟 — started 2015-11-24 0:29:14
版本:    Openfire 3.10.3
Openfire 主目录:    /opt/openfire
服务器名称:    localhost
所以是:
服务器中是localhost
去改为:
xmpp.domain to 192 168
然后再去代码中试试:
错误依旧。
抽空继续:
看看此错误相关的openfire的IP地址或者localhost方面的事情,估计是都设置了IP就可以了?
另外也去看看:是不是服务器密码是某种加密方式的,而此处是明文发送的,所以失败了?
看到官网的解释了:

If JID mapping is unsuccessful, then the server SHOULD return a SASL failure condition of <not-authorized/> and close the stream.

Example 16.

<failure xmlns=’urn:ietf:params:xml:ns:xmpp-sasl’>
<not-authorized/>
</failure>
</stream:stream>
所以:
此处是JID不匹配而导致此错误的。
然后去openfire后台确认当前是:
属性名    属性值    编辑    加密    删除
admin.authorizedJIDs
admin@localhost,root@localhost
属性名属性值编辑加密删除
admin.authorizedJIDs
admin@localhost,root@localhost
adminConsole.port
9090
adminConsole.securePort
9091
plugin.restapi.enabled
true
plugin.restapi.httpAuth
basic
xmpp.auth.anonymous
true
xmpp.domain
localhost
xmpp.httpbind.scriptSyntax.enabled
true
xmpp.session.conflict-limit
0
xmpp.socket.ssl.active
true
然后:
让别人去把openfire中的domain,全部都统一称为对应的此处的IP地址:
192.168.1.110
然后我代码中再去测试,看看是否可行。
Openfire中domain的已经都改为IP了:
属性名属性值编辑加密删除
admin.authorizedJIDs
xmpp.domain
192.168.1.110
另外,什么ElasticSearch说是也都更新domain为IP了。
然后代码即可正常执行了:
没有调用到(出错时才会执行的)didNotAuthenticate
而调用了:xmppStreamDidAuthenticate
[总结]
如此就说明:之前是由于XMPP服务器,此处的Openfire中的domain设置有误造成此问题的。
之前Openfire中的domain相关内容:
至少有:
admin.authorizedJIDs = admin@localhost,root@localhost
xmpp.domain =localhost
现在改为:
admin.authorizedJIDs = [email protected],[email protected]
xmpp.domain =192.168.1.110
其中,localhost改为XMPP服务器地址(Openfire所在服务器的IP地址:192.168.1.110)
之前和之后,各种XMPP客户端:
Spark,Mac的Aduim
都是可以正常登陆账号的
而此处的Mac开发中所用的,iOS的Swift的XMPP库:SwiftXMPP,中,对于之前的Openfire的domain是localhost的话:
对于代码来说:
登陆账号设置为:
xxx@localhost
还是:
xxx@服务器IP地址
结果都无法访问,因为:
如果代码中设置了xxx@localhost,那么代码中将无法解析localhost为主机的IP地址,从而无法访问服务器
如果代码设置了xxx@服务器IP地址,那么会由于此处服务器IP是对了,使得代码可以连接服务器,但是却和服务器端的domain是localhost不匹配,从而导致JID不匹配出错:<failure xmlns=”urn:ietf:params:xml:ns:xmpp-sasl”><not-authorized/></failure>
解决办法很简单:
就是XMPP服务器,此处deOpenfire中,把xmpp的domain部分,原先是localhost,改为主机的IP地址(此处的192.168.1.110)
从:
admin.authorizedJIDs = admin@localhost,root@localhost
xmpp.domain =localhost
改为:
admin.authorizedJIDs = [email protected],[email protected]
xmpp.domain =192.168.1.110
再重启XMPP服务器(Openfire),即可。
注:
此处顺带贴上,当前的Openfire的配置信息:
属性名属性值
admin.authorizedJIDs[email protected],[email protected]
adminConsole.port9090
adminConsole.securePort9091
connectionProvider.classNameorg.jivesoftware.database.EmbeddedConnectionProvider
httpbind.CORS.domains*
httpbind.CORS.enabledTRUE
httpbind.enabledTRUE
httpbind.forwarded.enabledFALSE
localezh_CN
passwordKeyhidden
plugin.restapi.allowedIPs 
plugin.restapi.enabledTRUE
plugin.restapi.httpAuthbasic
plugin.restapi.secretr1TKsFJ6ivNB3722
provider.admin.classNameorg.jivesoftware.openfire.admin.DefaultAdminProvider
provider.auth.classNameorg.jivesoftware.openfire.auth.DefaultAuthProvider
provider.group.classNameorg.jivesoftware.openfire.group.DefaultGroupProvider
provider.lockout.classNameorg.jivesoftware.openfire.lockout.DefaultLockOutProvider
provider.securityAudit.classNameorg.jivesoftware.openfire.security.DefaultSecurityAuditProvider
provider.user.classNameorg.jivesoftware.openfire.user.DefaultUserProvider
provider.vcard.classNameorg.jivesoftware.openfire.vcard.DefaultVCardProvider
setupTRUE
update.lastCheck1448418476089
xmpp.auth.anonymousTRUE
xmpp.domain192.168.1.110
xmpp.httpbind.scriptSyntax.enabledTRUE
xmpp.jmx.enabledFALSE
xmpp.jmx.port1099
xmpp.jmx.secureTRUE
xmpp.session.conflict-limit0
xmpp.socket.ssl.activeTRUE

转载请注明:在路上 » [已解决]swift中XMPP连接出错:

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.176 seconds, using 22.11MB memory