Android Smack Ejabberd多重连接问题

时间:2017-06-22 08:02:59

标签: android ejabberd smack asmack

我使用Ejabbered& amp;开发聊天应用程序在Android客户端上,每次用户输入应用程序我都会将我的状态发送给服务器&每次用户离开应用程序我都会将状态发送为不可用,这样我就可以收到之后发送的离线消息..但是虽然我在离开应用程序时发送了状态数据包,但当我从不同的位置检查时,我仍然可以看到用户在线客户。看着logcat我怀疑多个连接还活着:

已退出:

---------------------------------
06-22 12:36:42.473 2985-3052/ask.around D/SMACK: SENT (0): <presence id='R0C81-14' type='unavailable'><priority>1</priority><show>away</show></presence><r xmlns='urn:xmpp:sm:3'/>
06-22 12:36:42.474 2985-3052/ask.around D/SMACK: SENT (0): <presence id='R0C81-15' type='unavailable'></presence>
06-22 12:36:42.475 2985-3052/ask.around D/SMACK: SENT (0): <a xmlns='urn:xmpp:sm:3' h='5'/>
06-22 12:36:42.486 2985-3052/ask.around D/SMACK: SENT (0): 
06-22 12:36:42.487 2985-3052/ask.around D/SMACK: SENT (0): </stream:stream>
06-22 12:36:42.616 2985-3053/ask.around D/SMACK: RECV (0): <a h='5' xmlns='urn:xmpp:sm:3'/>
06-22 12:36:42.692 2985-3053/ask.around D/SMACK: RECV (0): </stream:stream>
06-22 12:36:42.693 2985-3271/ask.around D/SMACK: XMPPConnection closed (XMPPTCPConnection[moulesh@ask-around-chat/48305568695274620153122] (0))

未注销:

06-22 12:02:01.952 2586-3299/ask.around D/SMACK: SENT (2): <presence id='86IU1-48' type='unavailable'><priority>1</priority><show>away</show></presence><r xmlns='urn:xmpp:sm:3'/><presence id='86IU1-49' type='unavailable'></presence><a xmlns='urn:xmpp:sm:3' h='6'/>
06-22 12:02:01.952 2586-3299/ask.around D/SMACK: SENT (2): </stream:stream>
06-22 12:02:02.032 2586-3300/ask.around D/SMACK: RECV (2): <a h='5' xmlns='urn:xmpp:sm:3'/>
06-22 12:02:02.052 2586-3282/ask.around D/SMACK: RECV (1): <presence xml:lang='en' to='moulesh@ask-around-chat/104236288900606474493066' from='moulesh@ask-around-chat/105858598794378801093074' type='unavailable' id='86IU1-48'><priority>1</priority><show>away</show></presence><r xmlns='urn:xmpp:sm:3'/>
06-22 12:02:02.053 2586-3281/ask.around D/SMACK: SENT (1): <a xmlns='urn:xmpp:sm:3' h='7'/>
06-22 12:02:02.099 2586-3300/ask.around D/SMACK: RECV (2): </stream:stream>
06-22 12:02:02.100 2586-2938/ask.around D/SMACK: XMPPConnection closed (XMPPTCPConnection[moulesh@ask-around-chat/105858598794378801093074] (2))

我犯的错误是什么,我注意到在注销成功注销时,数字总是为零,n在不成功的注册中它的最多为2,所以我创建了多个连接?或者数字不是连接数?如果它是连接数问题如何在我的应用程序活着之前创建一个单独的n实例?

1 个答案:

答案 0 :(得分:0)

你可以在连接之前喊出旧实例。这可能对你有所帮助。

if(mXmpptcpConnection!=null){
        mXmpptcpConnection.instantShutdown();
    }