Strophe反复重连openfire的问题

1 问题描述
使用Strophe连接openfire,成功连接后。登录到openfire管理控制台,删除此人的会话,出现的现象是,Strophe重新连接openfire,但是连接成功,会立马断开连接,然后重连服务器
js异常
错误信息

2016.09.21 11:41:58 org.jivesoftware.openfire.http.HttpBindServlet - Error sending packet to client. 
org.jivesoftware.openfire.http.HttpConnectionClosedException: The http connection is no longer available to deliver content 
at org.jivesoftware.openfire.http.HttpConnection.deliverBody(HttpConnection.java:116) 
at org.jivesoftware.openfire.http.HttpSession.forwardRequest(HttpSession.java:604) 
at org.jivesoftware.openfire.http.HttpBindServlet.handleSessionRequest(HttpBindServlet.java:250) 
at org.jivesoftware.openfire.http.HttpBindServlet.processContent(HttpBindServlet.java:205) 
at org.jivesoftware.openfire.http.HttpBindServlet$ReadListenerImpl.onAllDataRead(HttpBindServlet.java:423)

警告信息

2016.09.21 13:01:54 org.jivesoftware.openfire.IQRouter - User tried to authenticate with this server using an unknown receipient: <iq type="get" to="1@192.168.4.187/Strophe" id="78e40236-b8f9-4205-8088-55249c2365ad:ping" from="192.168.4.187/y7uect7v1"><ping xmlns="urn:xmpp:ping"/></iq> 

监控openfire接受的报文,收到的都是这样的信息

<iq type="get" to="1@192.168.4.187/Strophe" id="c0c40a9a-8c6c-4a68-ac32-523cec4d8104:ping" from="192.168.4.187/y7uect7v1"> 
<ping xmlns="urn:xmpp:ping"/> 
</iq> 

发送iq请求的js代码如下:

checkSeatOnline:function(to){
        var seat = to+self.openfirefix;                                                                                                                                                                                                                                                                                                                                                            
        var _success = function(resp){                                                                                                                                                                                    
            console.log(resp);                                                                                                                                                                                              
        }                                                                                                                                                                                                                 
        var _error = function(resp){                                                                                                                                                                                      
            console.log(resp);                                                                                                                                                                                              
            window.clearInterval(self.seatOutLine);                                                                                                                                                                              
            $.closeModal();                                                                                                                                                                                                 
            $.confirm('客服已断开连接,是否重新连接?',function(){                                                                                                                                                           
                 window.location.reload();                                                                                                                                                                                    
            },function(){                                                                                                                                                                                                   
                self.connection.disconnect("客服已断开");                                                                                                                                                                                
                self.openScoreDialog();                                                                                                                                                                                                    
            });                                                                                                                                                                                                             
        }                                                                                                                                                                                                                 
        self.connection.ping.ping(seat,_success, _error);               
    }

2 问题分析
正常的发送消息,收到多条相同的iq节或message节。非常奇怪。
正常的iq
正常的message
查看Strophe.js源码
Strophe.Connection中会启动一个空闲检测,检测时间为100ms。

this._idleTimeout = setTimeout(function() {
        this._onIdle();
    }.bind(this), 100);

在分析_onIdle的代码,如果连接成功后,100ms还会循环调用空闲检测。

 if (this.connected) {
            // XXX: setTimeout should be called only with function expressions (23974bc1)
            this._idleTimeout = setTimeout(function() {
                this._onIdle();
            }.bind(this), 100);
        }

根据现象推送原因,我们自己写的断开重连的方法,与openfire的空闲检测,因为时间差的问题,导致openfire反复重连。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

warrah

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值