关于strophe 通过 connection manager 连接到 openfire server 失败 的原因初阶分析http://xmpp.org/extensions/xep-0206.ht

本文详细阐述了使用BOSH协议通过connectionmanager连接到Openfire时遇到的挑战,特别是针对第三步重启请求后connectionmanager不再返回任何数据直至超时的情况。文章深入分析了这一现象,并对比了strophe和JSJaC库的不同处理方式,最终提供了一个自定义js文件修复此问题的解决方案,同时附上了下载链接。

参考

协议 XMPP XEP-0206 (BOSH)

http://xmpp.org/extensions/xep-0206.html


通过BOSH 创建 会话经历的一般步骤包括

(1)Session Creation 会话创建请求

(2)Authentication 身份验证

(3)Restart request 重启请求

(4)Resource binding request资源绑定请求


问题就出现在第三步的时候,之前步骤都是正确的

参考strophe不通过connection manager 连接到openfire的时候走的就是这个标准流程


(3)(4)数据流如下

(3)Restart request 重启请求
request:
<body rid='539419237' xmlns='http://jabber.org/protocol/httpbind' sid='e957c613'
to='tes-pc-10-05' xml:lang='en' xmpp:restart='true' xmlns:xmpp='urn:xmpp:xbosh'/>


response:
<body xmlns="http://jabber.org/protocol/httpbind" xmlns:stream="http://etherx.jabber.org/streams">
<stream:features>
<compression xmlns="http://jabber.org/features/compress">
<method>zlib</method>
</compression>
<bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/>
<session xmlns="urn:ietf:params:xml:ns:xmpp-session"/>
</stream:features>
</body>

(4)Resource binding request资源绑定请求
request:
<body rid='539419238' xmlns='http://jabber.org/protocol/httpbind' sid='e957c613'>
<iq type='set' id='_bind_auth_2' xmlns='jabber:client'>
<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>
</iq>
</body>

response:
<body xmlns='http://jabber.org/protocol/httpbind'>
<iq xmlns="jabber:client" type="result" id="_bind_auth_2" to="tes-pc-10-05/e957c613">
<bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
<jid>a@tes-pc-10-05/e957c613</jid>
</bind>
</iq>
</body>


而 connectionmanager 在 3之后就不再返回任何数据一直到超时。


而另外一个库JSJaC,则可以顺利通过 connection manager连上openfire 这是因为

他把3,4合并在一起执行了

数据流如下

request:
<body 
rid='812216' 
sid='cjyvqeef8619c' 
xmlns='http://jabber.org/protocol/httpbind' 
key='e6711e9a605a2a1a28257baa57ee7fc69e5eea86' 
xmpp:restart='true' <!--  重启请求-->
xmlns:xmpp='urn:xmpp:xbosh'>

<!-- 资源绑定-->
<iq xmlns="jabber:client" type="set" id="bind_1">
<bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
<resource xmlns="urn:ietf:params:xml:ns:xmpp-bind">jsjac_simpleclient</resource>
</bind>
</iq>

</body>

response:
<body xmlns='http://jabber.org/protocol/httpbind'>
<iq type="result" id="bind_1" to="tes-pc-10-05/cjyvqeef8619c">
<bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
<jid>a@tes-pc-10-05/jsjac_simpleclient</jid>
</bind>
</iq>
</body>

我自己编写了一个js文件修复了这个问题,上传到了我的资源。

下载地址  http://download.youkuaiyun.com/detail/suncaishen/4282736

<?php // 数据库配置 define('DB_HOST', 'localhost'); define('DB_USER', 'szrengjing_com'); define('DB_PASS', 'ZparETNy4DTZBAiT'); define('DB_NAME', 'szrengjing_com'); define('ADMIN_PATH', dirname(__FILE__).'/../admin/'); // 表名定义 define('TABLE_MERCHANT', 'ecs_merchant'); define('TABLE_CUSTOMER_SERVICE', 'ecs_chat_customer'); define('TABLE_THIRD_CUSTOMER', 'ecs_chat_third_customer'); define('TABLE_CHAT_SESSION', 'ecs_chat'); define('TABLE_CHAT_MESSAGE', 'ecs_chat_message'); // 时区设置 date_default_timezone_set('Asia/Shanghai'); // 错误报告设置 error_reporting(E_ALL & ~E_DEPRECATED); ini_set('display_errors', 1); ini_set('session.cookie_httponly', 1); ini_set('session.use_only_cookies', 1); ?> 服务器属性 服务器正常运行时间: 5 天, 16 小时, 18 分钟 -- started 2025年8月1日 下午6:10:35 版本: Openfire 4.9.2 服务目录: /opt/openfire XMPP 域名: localhost 环境 Java 版本: 11.0.13 Red Hat, Inc. -- OpenJDK 64-Bit Server VM 应用服务器: jetty/10.0.18 服务器主机名(FQDN): localhost 操作系统/硬件: Linux / amd64 区域设置/时区: zh_CN / 中国标准时间 (8 GMT) 操作系统进程所有者: openfire JavaXMPP-Web 客户端配置 此页面允许您配置 XMPP-Web 聊天应用程序。 最终用户可以通过在浏览器中打开以下地址来使用 XMPP-Web(使用未加密的 HTTP 连接):http://localhost:7070/xmppweb/。 XMPP-Web 可通过加密的 HTTPS 地址访问:https://localhost:7443/xmppweb/。 Web 客户端设置 使用此表单可将配置更改应用于 XMPP-Web 客户端。 应用程序名称 人进商城在线客服 设置为false可禁用已注册用户组件(仅限客人访问) 应用程序使用的 Websocket 端点(代理或直接 XMPP 服务器) wss://zxkf.szrengjing.com:7443/ws/ 应用程序使用的 BOSH 端点(代理或直接 XMPP 服务器http://124.71.230.244:7070/xmppweb/ 用于客人访问的虚拟主机(匿名) 如何配置连接
最新发布
08-08
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值