android im英雄联盟掉线崩溃会导致程序崩溃吗

你的浏览器禁用了JavaScript, 请开启后刷新浏览器获得更好的体验!
10-15 11:52:29.602 /com.remair.borrowme I/sxmppcon: enter disconnect ()
10-15 11:52:29.762 /com.remair.borrowme I/sxmppcon: shutdown was called
10-15 11:52:29.762 /com.remair.borrowme W/System.err: com.easemob.exceptions.EMNetworkUnconnectedException: java.net.ConnectException: failed to connect to /182.92.23.59 (port 443) after 40000ms: isConnected failed: ECONNREFUSED (Connection refused)
10-15 11:52:29.762 /com.remair.borrowme W/System.err:
at com.easemob.chat.core.EMConnectionManager.connect(Unknown Source)
10-15 11:52:29.762 /com.remair.borrowme W/System.err:
at com.easemob.chat.core.EMConnectionManager.connectSync(Unknown Source)
10-15 11:52:29.762 /com.remair.borrowme W/System.err:
at com.easemob.chat.core.EMConnectionManager.reconnectSync(Unknown Source)
10-15 11:52:29.762 /com.remair.borrowme W/System.err:
at com.easemob.chat.core.EMConnectionManager$3.run(Unknown Source)
10-15 11:52:38.852 /com.remair.borrowme I/sxmppcon: enter disconnect ()
10-15 11:52:39.012 /com.remair.borrowme I/sxmppcon: shutdown was called
10-15 11:52:39.022 /com.remair.borrowme W/System.err: com.easemob.exceptions.EMNetworkUnconnectedException: java.net.ConnectException: failed to connect to /182.92.20.117 (port 443) after 40000ms: isConnected failed: ECONNREFUSED (Connection refused)
10-15 11:52:39.022 /com.remair.borrowme W/System.err:
at com.easemob.chat.core.EMConnectionManager.connect(Unknown Source)
10-15 11:52:39.022 /com.remair.borrowme W/System.err:
at com.easemob.chat.core.EMConnectionManager.connectSync(Unknown Source)
10-15 11:52:39.022 /com.remair.borrowme W/System.err:
at com.easemob.chat.core.EMConnectionManager.reconnectSync(Unknown Source)
10-15 11:52:39.022 /com.remair.borrowme W/System.err:
at com.easemob.chat.core.EMConnectionManager$3.run(Unknown Source)
10-15 11:52:45.082 /com.remair.borrowme I/sxmppcon: enter disconnect ()
10-15 11:52:45.242 /com.remair.borrowme I/sxmppcon: shutdown was called
10-15 11:52:45.242 /com.remair.borrowme W/System.err: com.easemob.exceptions.EMNetworkUnconnectedException: java.net.ConnectException: failed to connect to /182.92.23.59 (port 5222) after 40000ms: isConnected failed: ECONNREFUSED (Connection refused)
10-15 11:52:45.242 /com.remair.borrowme W/System.err:
at com.easemob.chat.core.EMConnectionManager.connect(Unknown Source)
10-15 11:52:45.242 /com.remair.borrowme W/System.err:
at com.easemob.chat.core.EMConnectionManager.connectSync(Unknown Source)
10-15 11:52:45.242 /com.remair.borrowme W/System.err:
at com.easemob.chat.core.EMConnectionManager.reconnectSync(Unknown Source)
10-15 11:52:45.242 /com.remair.borrowme W/System.err:
at com.easemob.chat.core.EMConnectionManager$3.run(Unknown Source)
周期性的输出这个,25秒一次
换个网络试试
我这也出现了,不知道是不是环信服务器出问题了,但是IOS版的又能登录。
从报错log上并不能看也导致掉线的原因是什么,导致掉线的原因也不是固定只有一种,你们测试的是自己的app还是Demo,如果demo没问题,可能你的代码处理逻辑有关,还有你集成的SDK版本是多少? 这个需要诊断定位来排查的,如果更详细的沟通这个问题,也可联系我们的客服,或者在官网下方寻求一下在线技术支持。
今天抓了下日志,发现只要服务器没有应道心跳包,就收不到消息,并且关掉当前socket,开启新的socket后,服务器马上有应答,这说明不是网络的问题。另外官方demo也存在这样的问题。想到的解决办法就是app收不到消息的时候强行调用环信的登陆。如果有跟好的解决办法,欢迎讨论。附上日志:
12-08 17:43:52.974: D/EMHeartBeatReceiver(23769): onReceive EMHeartBeatReceiver
12-08 17:43:52.989: D/smart ping(23769): post heartbeat runnable
12-08 17:43:52.994: D/net(23769): has wifi connection
12-08 17:43:52.999: D/smart ping(23769): has network connection:true has data conn:true isConnected to easemob server : true
12-08 17:43:52.999: D/net(23769): has wifi connection
12-08 17:43:52.999: D/smart ping(23769): check pingpong ...
12-08 17:43:53.999: D/smart ping(23769): send ping-pong type heartbeat
12-08 17:43:54.009: D/SMACK:FileDebugger(23769):
SENT to182.92.20.117:443(): &iq id=&0b8eB-5& type=&get&&&ping xmlns='urn:xmpp:ping' /&&/iq&
12-08 17:44:09.009: D/smart ping(23769): no result while send ping-pong
12-08 17:44:10.019: D/smart ping(23769): send ping-pong type heartbeat
12-08 17:44:10.019: D/SMACK:FileDebugger(23769):
SENT to182.92.20.117:443(): &iq id=&0b8eB-5& type=&get&&&ping xmlns='urn:xmpp:ping' /&&/iq&
12-08 17:44:25.024: D/smart ping(23769): no result while send ping-pong
12-08 17:44:26.034: D/smart ping(23769): send ping-pong type heartbeat
12-08 17:44:26.044: D/SMACK:FileDebugger(23769):
SENT to182.92.20.117:443(): &iq id=&0b8eB-5& type=&get&&&ping xmlns='urn:xmpp:ping' /&&/iq&
12-08 17:44:41.044: D/smart ping(23769): no result while send ping-pong
12-08 17:44:42.054: D/smart ping(23769): send ping-pong type heartbeat
12-08 17:44:42.064: D/SMACK:FileDebugger(23769):
SENT to182.92.20.117:443(): &iq id=&0b8eB-5& type=&get&&&ping xmlns='urn:xmpp:ping' /&&/iq&
12-08 17:44:57.064: D/smart ping(23769): no result while send ping-pong
12-08 17:44:57.084: D/smart ping(23769): failed to send ping pong ... with current heartbeat interval : 03:30:000
12-08 17:44:57.094: D/net(23769): has wifi connection
12-08 17:44:57.099: D/smart ping(23769): send ping-pong failed, but has success interval candiate with ping state : EMEvaluating enter EMSmartPingState.EMReevaluating
12-08 17:44:57.104: D/smart ping(23769): change smart ping state from : EMEvaluating to : EMReevaluating
12-08 17:44:57.114: D/EMChatManager(23769): manually force to reconnect to server
12-08 17:44:57.114: D/EMConnectionManager(23769): enter reConnect
12-08 17:44:57.124: I/sxmppcon(23769): enter disconnect ()
12-08 17:44:57.129: D/sxmppcon(23769): () shutdown
12-08 17:44:57.139: D/SMACK:FileDebugger(23769):
SENT to182.92.20.117:443(): &presence id=&0b8eB-6& type=&unavailable&&&/presence&
12-08 17:44:57.139: D/EMConnectionManager(23769): connectionClosed
12-08 17:44:57.149: D/EMConnectionManager(23769): on disconnected
12-08 17:44:57.159: D/SMACK:FileDebugger(23769):
Connection closed ()
12-08 17:44:57.169: D/SMACK:FileDebugger(23769):
SENT to182.92.20.117:443(): &/stream:stream&
12-08 17:44:57.319: D/sxmppcon(23769): trying to close the socket : Socket[address=/182.92.20.117,port=443,localPort=57759]
12-08 17:44:57.324: D/sxmppcon(23769): () socket was closed
12-08 17:44:57.324: I/sxmppcon(23769): shutdown was called
12-08 17:44:57.324: D/EMConnectionManager(23769): register connectivity receiver.
12-08 17:44:57.334: D/EMConnectionManager(23769): connectivity receiver onReceiver
12-08 17:44:57.334: D/EMConnectionManager(23769):
: enter startReconnectionThread()
12-08 17:44:57.339: D/net(23769): has wifi connection
12-08 17:44:57.339: D/net(23769): has wifi connection
12-08 17:44:57.344: D/EMConnectionManager(23769): start reconnectionThread()
12-08 17:44:57.349: D/smart ping(23769): schedule next alarm
12-08 17:44:57.349: D/smart ping(23769): current heartbeat interval : 03:00:000 smart ping state : EMReevaluating
12-08 17:44:57.354: D/EMConnectionManager(23769): run in reconnectionThread
12-08 17:44:57.359: D/net(23769): has wifi connection
12-08 17:44:57.359: D/smart ping(23769): is not connected to server, so use idle interval : 3 mins
12-08 17:44:58.414: D/EMConnectionManager(23769): run in reconnectionThread with connection
12-08 17:44:58.424: D/net(23769): has wifi connection
12-08 17:44:58.429: D/EMConnectionManager(23769): try to reconnectSync
12-08 17:44:58.434: D/EMConnectionManager(23769): enter connectSync
12-08 17:44:58.444: D/EMConnectionManager(23769): connection manager:connect
12-08 17:44:58.444: D/EMConnectionManager(23769): before connect
12-08 17:44:58.449: D/sxmppcon(23769): try to connect to host : 182.92.20.117 port : 443
12-08 17:44:58.494: D/sxmppcon(23769): open a new socket : Socket[address=/182.92.20.117,port=443,localPort=36494]
12-08 17:44:58.509: D/SMACK:FileDebugger(23769):
SENT to182.92.20.117:443(): &stream:stream to=&& xmlns=&jabber:client& xmlns:stream=& version=&1.0&&
12-08 17:44:58.554: D/SMACK:FileDebugger(23769):
RCV from182.92.20.117:443(): &?xml version='1.0'?&&stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='' from='' version='1.0' xml:lang='en'&&stream:features&&compression xmlns='http://jabber.org/features/compress'&&method&zlib&/method&&/compression&&mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'&&mechanism&PLAIN&/mechanism&&/mechanisms&&c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='/' ver='pNSTsv0+8X2VCrBE7jESku4qtkk='/&&register xmlns='http://jabber.org/features/iq-register'/&&/stream:features&
12-08 17:44:58.569: D/SMACK:FileDebugger(23769):
SENT to182.92.20.117:443(): &compress xmlns='http://jabber.org/protocol/compress'&
12-08 17:44:58.574: D/SMACK:FileDebugger(23769):
SENT to182.92.20.117:443(): &method&zlib&/method&&/compress&
12-08 17:44:58.809: D/SMACK:FileDebugger(23769):
RCV from182.92.20.117:443(): &compressed xmlns='http://jabber.org/protocol/compress'/&
12-08 17:44:58.809: D/SMACK:FileDebugger(23769):
SENT to182.92.20.117:443(): &stream:stream to=&& xmlns=&jabber:client& xmlns:stream=& version=&1.0&&
12-08 17:44:58.819: D/SASLAuthentication(23769): waiting for authentiation response!
12-08 17:44:58.824: D/SMACK:FileDebugger(23769):
SENT to182.92.20.117:443(): &auth mechanism=&PLAIN& xmlns=&urn:ietf:params:xml:ns:xmpp-sasl&&c3RudHMjdGl0YXRlc3RfdGl0YV8xMDAwNTAAc3RudHMjdGl0YXRlc3RfdGl0YV8xMDAwNTAAc0dLc0dYUkUxWWtlb0tKTEhXRE5IUT09&/auth&
12-08 17:44:58.884: D/SMACK:FileDebugger(23769):
RCV from182.92.20.117:443(): &?xml version='1.0'?&&stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='' from='' version='1.0' xml:lang='en'&
12-08 17:44:58.904: D/SMACK:FileDebugger(23769):
RCV from182.92.20.117:443(): &stream:features&&mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'&&mechanism&PLAIN&/mechanism&&/mechanisms&&c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='/' ver='pNSTsv0+8X2VCrBE7jESku4qtkk='/&&register xmlns='http://jabber.org/features/iq-register'/&&/stream:features&&success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/&
12-08 17:44:58.929: D/SMACK:FileDebugger(23769):
SENT to182.92.20.117:443(): &stream:stream to=&& xmlns=&jabber:client& xmlns:stream=& version=&1.0&&
12-08 17:44:59.004: D/SMACK:FileDebugger(23769):
RCV from182.92.20.117:443(): &?xml version='1.0'?&&stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='' from='' version='1.0' xml:lang='en'&
12-08 17:44:59.024: D/dalvikvm(23769): GC_CONCURRENT freed 2015K, 26% free 2K, paused 22ms+15ms, total 136ms
12-08 17:44:59.024: D/dalvikvm(23769): WAIT_FOR_CONCURRENT_GC blocked 17ms
12-08 17:44:59.024: D/dalvikvm(23769): WAIT_FOR_CONCURRENT_GC blocked 18ms
12-08 17:44:59.034: D/SMACK:FileDebugger(23769):
RCV from182.92.20.117:443(): &stream:features&&bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/&&session xmlns='urn:ietf:params:xml:ns:xmpp-session'/&&ver xmlns='urn:xmpp:features:rosterver'/&&c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='/' ver='pNSTsv0+8X2VCrBE7jESku4qtkk='/&&register xmlns='http://jabber.org/features/iq-register'/&&/stream:features&
12-08 17:44:59.039: D/SMACK:FileDebugger(23769):
SENT to182.92.20.117:443(): &iq id=&0b8eB-8& type=&set&&&bind xmlns=&urn:ietf:params:xml:ns:xmpp-bind&&&resource&mobile&/resource&&/bind&&/iq&
12-08 17:44:59.074: D/SMACK:FileDebugger(23769):
RCV from182.92.20.117:443(): &iq id='0b8eB-8' type='result'&&bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'&&jid&/mobile&/jid&&/bind&&/iq&
12-08 17:44:59.074: D/SMACK:FileDebugger(23769):
SENT to182.92.20.117:443(): &iq id=&0b8eB-9& type=&set&&&session xmlns=&urn:ietf:params:xml:ns:xmpp-session&/&&/iq&
12-08 17:44:59.109: D/SMACK:FileDebugger(23769):
RCV from182.92.20.117:443(): &iq type='result' id='0b8eB-9'/&
12-08 17:44:59.114: D/SMACK:FileDebugger(23769): User logged (): @:443/mobile
12-08 17:44:59.114: D/EMConnectionManager(23769): reconnectionSuccessful
12-08 17:44:59.119: D/EMConnectionManager(23769): send version iq
12-08 17:44:59.119: D/SMACK:FileDebugger(23769):
SENT to182.92.20.117:443(): &iq id=&0b8eB-10& to=&& from=&@& type=&result&&&query xmlns=&jabber:iq:version&&&name&easemob&/name&&version&2.2.4&/version&&os&android&/os&&/query&&/iq&
12-08 17:44:59.124: D/EMConnectionManager(23769): send available presence after reconnected
12-08 17:44:59.124: D/SMACK:FileDebugger(23769):
SENT to182.92.20.117:443(): &presence id=&0b8eB-11&&&/presence&
12-08 17:44:59.124: D/EMChatManager(23769): reconnectionSuccessful
12-08 17:44:59.129: D/SMACK:FileDebugger(23769):
Connection reconnected ()
12-08 17:44:59.129: D/EMConnectionManager(23769): after connect
12-08 17:44:59.129: D/EMConnectionManager(23769): enter initConnection()
12-08 17:44:59.134: D/EMConnectionManager(23769): already login. skip
12-08 17:44:59.134: D/[Collector][Login][im login time](23769): im login time : 00:00:690
12-08 17:44:59.134: D/smart ping(23769):
onConnectred ...
12-08 17:44:59.134: D/EMChatManager(23769): onConnectionSuccessful
12-08 17:44:59.134: D/smart ping(23769): schedule next alarm
12-08 17:44:59.139: D/smart ping(23769): current heartbeat interval : 03:00:000 smart ping state : EMReevaluating
12-08 17:44:59.139: D/sender(23769): start flush Pending Queue
12-08 17:44:59.144: D/net(23769): has wifi connection
12-08 17:44:59.144: I/(23769): ################################
12-08 17:44:59.144: I/(23769): ############聊天服务器已连接############
12-08 17:44:59.144: I/(23769): ####################################
12-08 17:44:59.154: D/smart ping(23769):
onConnectred ...
12-08 17:44:59.159: D/smart ping(23769): schedule next alarm
12-08 17:44:59.159: D/smart ping(23769): current heartbeat interval : 03:00:000 smart ping state : EMReevaluating
12-08 17:44:59.159: D/net(23769): has wifi connection
12-08 17:44:59.189: I/(23769): ################################
12-08 17:44:59.189: I/(23769): ############聊天服务器已连接############
12-08 17:44:59.189: I/(23769): ####################################
12-08 17:44:59.279: D/SMACK:FileDebugger(23769):
RCV from182.92.20.117:443(): &message from='stnts#@' to='stnts#@' id='339956' type='chat'&&body&{&from&:&&,&to&:&&,&bodies&:[{&type&:&txt&,&msg&:&:smiley::wink::disappointed_relieved::joy:&}],&ext&:{&user_game_nickname&:&啦啦&,&qd_id&:&100062&,&msg_user_icon&:&3405581.jpg&,&msg_user_name&:&啦啦&,&groupType&:&&}}&/body&&thread&56DDR0&/thread&&delay xmlns='urn:xmpp:delay' stamp='T09:42:31.486Z'/&&/message&
12-08 17:44:59.284: D/chat(23769): temp acquire 3s
12-08 17:44:59.289: D/chat(23769): send ack message back to server:org.jivesoftware.smack.packet.Message@b4fff167
12-08 17:44:59.289: D/SMACK:FileDebugger(23769):
SENT to182.92.20.117:443(): &message id=&339956& to=&& from=&stnts#@&&&received xmlns=&urn:xmpp:receipts& id=&339956&/&&/message&
12-08 17:44:59.294: D/chat(23769): chat listener receive msg from:stnts#@ body:{&from&:&&,&to&:&&,&bodies&:[{&type&:&txt&,&msg&:&:smiley::wink::disappointed_relieved::joy:&}],&ext&:{&user_game_nickname&:&啦啦&,&qd_id&:&100062&,&msg_user_icon&:&3405581.jpg&,&msg_user_name&:&啦啦&,&groupType&:&&}}
12-08 17:44:59.294: D/EMConversationManager(23769): save message:339956
12-08 17:44:59.294: D/EMConversationManager(23769): get conversation for user:
12-08 17:44:59.299: D/EMDBManager(23769): add converstion with:
12-08 17:44:59.304: D/SMACK:FileDebugger(23769):
RCV from182.92.20.117:443(): &message from='stnts#@' to='stnts#@' id='055796' type='chat'&&body&{&from&:&&,&to&:&&,&bodies&:[{&type&:&txt&,&msg&:&:sweat::sleeping::fearful::scream::scream:&}],&ext&:{&user_game_nickname&:&啦啦&,&qd_id&:&100062&,&msg_user_icon&:&3405581.jpg&,&msg_user_name&:&啦啦&,&groupType&:&&}}&/body&&thread&56DDR0&/thread&&delay xmlns='urn:xmpp:delay' stamp='T09:42:34.623Z'/&&/message&&message from='stnts#@' to='stnts#@' id='751988' type='chat'&&body&{&from&:&&,&to&:&&,&bodies&:[{&type&:&txt&,&msg&:&:heart::heart::heart::heart::heart::heart:&}],&ext&:{&user_game_nickname&:&啦啦&,&qd_id&:&100062&,&msg_user_icon&:&3405581.jpg&,&msg_user_name&:&啦啦&,&groupType&:&&}}&/body&&thread&56DDR0&/thread&&delay xmlns='urn:xmpp:delay' stamp='T09:42:46.783Z'/&&/message&
12-08 17:44:59.309: D/EMDBManager(23769): save msg to db
12-08 17:44:59.314: D/EMDBManager(23769): add converstion with:
12-08 17:44:59.319: D/EMOfflineMessageHandler(23769):
offline msg, do not send notify for msg:339956
12-08 17:44:59.324: D/EMOfflineMessageHandler(23769): start offline notify thread...
12-08 17:44:59.324: D/SMACK:FileDebugger(23769):
SENT to182.92.20.117:443(): &message id=&055796& to=&& from=&stnts#@&&&received xmlns=&urn:xmpp:receipts& id=&055796&/&&/message&
12-08 17:44:59.324: D/chat(23769): send ack message back to server:org.jivesoftware.smack.packet.Message@b4fff167
12-08 17:44:59.324: D/chat(23769): chat listener receive msg from:stnts#@ body:{&from&:&&,&to&:&&,&bodies&:[{&type&:&txt&,&msg&:&:sweat::sleeping::fearful::scream::scream:&}],&ext&:{&user_game_nickname&:&啦啦&,&qd_id&:&100062&,&msg_user_icon&:&3405581.jpg&,&msg_user_name&:&啦啦&,&groupType&:&&}}
12-08 17:44:59.324: D/EMConversationManager(23769): save message:055796
12-08 17:44:59.329: D/EMConversationManager(23769): get conversation for user:
12-08 17:44:59.329: D/EMDBManager(23769): add converstion with:
12-08 17:44:59.334: D/EMDBManager(23769): save msg to db
12-08 17:44:59.334: D/EMDBManager(23769): add converstion with:
12-08 17:44:59.339: D/EMOfflineMessageHandler(23769):
offline msg, do not send notify for msg:055796
12-08 17:44:59.339: D/SMACK:FileDebugger(23769):
SENT to182.92.20.117:443(): &message id=&751988& to=&& from=&stnts#@&&&received xmlns=&urn:xmpp:receipts& id=&751988&/&&/message&
12-08 17:44:59.339: D/chat(23769): send ack message back to server:org.jivesoftware.smack.packet.Message@b4fff167
12-08 17:44:59.339: D/chat(23769): chat listener receive msg from:stnts# body:{&from&:&&,&to&:&&,&bodies&:[{&type&:&txt&,&msg&:&:heart::heart::heart::heart::heart::heart:&}],&ext&:{&user_game_nickname&:&啦啦&,&qd_id&:&100062&,&msg_user_icon&:&3405581.jpg&,&msg_user_name&:&啦啦&,&groupType&:&&}}
12-08 17:44:59.344: D/EMConversationManager(23769): save message:751988
12-08 17:44:59.344: D/EMConversationManager(23769): get conversation for user:
12-08 17:44:59.349: D/EMDBManager(23769): add converstion with:ti
12-08 17:44:59.354: D/EMDBManager(23769): save msg to db
12-08 17:44:59.354: D/EMDBManager(23769): add converstion with:
12-08 17:44:59.354: D/EMOfflineMessageHandler(23769):
offline msg, do not send notify for msg:751988
12-08 17:45:02.329: D/EMOfflineMessageHandler(23769): send offline message broadcast for users:1
12-08 17:45:02.339: D/EMOfflineMessageHandler(23769): send offline message broadcast for groups:0
12-08 17:45:02.359: D/EMChatManager(23769): broad offline msg
12-08 17:45:02.379: D/notify(23769): send new message broadcast for msg:751988
12-08 17:45:02.394: D/notify(23769): publish event, event type: EventOfflineMessage
要回复问题请先或
浏览: 3352
关注: 6 人
知识价值的认可,源自您的赞赏
扫描二维码,你的支付将由imGeek代收后转给对方
感谢您的赞赏
一个开放、互助、协作、创意的社区
一个开放、互助、协作、创意的社区
京ICP备号-3Android基于XMPP Smack Openfire下学习开发IM(五)连接断开重连
学习过程中大家都碰到过连接被断开的问题给困扰吧,下面教大家如何做到连接断开后,重新连接
首先要创建连接监听器,用来监听连接状态,这里我写了一个类
继承了ConnectionListener,重写了里面5个方法,最重要的两个方法connectionClosed()和connectionClosedOnError()
前者为连接正常断开,后者是连接异常断开,不管是正常还是异常,我们都要监听到
这里写了一个定时器,两秒进行连接一次,注释写的也很清楚,不做太多介绍
要注意的是我把用户名和密码都存到sharePreferences中了
package com.techrare. &
import java.util.T &
import java.util.TimerT &
import org.jivesoftware.smack.ConnectionL &
import android.util.L &
import com.techrare.taxicall.MainA &
import com.techrare.utils.U &
import com.techrare.utils.XmppC &
&* 连接监听类&
&* @author Administrator&
public class TaxiConnectionListener implements ConnectionListener { &
& & private Timer tE &
& & private S &
& & private S &
& & private int logintime = 2000; &
& & @Override &
& & public void connectionClosed() { &
& & & & Log.i(&TaxiConnectionListener&, &連接關閉&); &
& & & & // 關閉連接 &
& & & & XmppConnection.getInstance().closeConnection(); &
& & & & // 重连服务器 &
& & & & tExit = new Timer(); &
& & & & tExit.schedule(new timetask(), logintime); &
& & @Override &
& & public void connectionClosedOnError(Exception e) { &
& & & & Log.i(&TaxiConnectionListener&, &連接關閉異常&); &
& & & & // 判斷為帳號已被登錄 &
& & & & boolean error = e.getMessage().equals(&stream:error (conflict)&); &
& & & & if (!error) { &
& & & & & & // 關閉連接 &
& & & & & & XmppConnection.getInstance().closeConnection(); &
& & & & & & // 重连服务器 &
& & & & & & tExit = new Timer(); &
& & & & & & tExit.schedule(new timetask(), logintime); &
& & & & } &
& & class timetask extends TimerTask { &
& & & & @Override &
& & & & public void run() { &
& & & & & & username = Utils.getInstance().getSharedPreferences(&taxicall&, &
& & & & & & & & & & &account&, MainActivity.context); &
& & & & & & password = Utils.getInstance().getSharedPreferences(&taxicall&, &
& & & & & & & & & & &password&, MainActivity.context); &
& & & & & & if (username != null && password != null) { &
& & & & & & & & Log.i(&TaxiConnectionListener&, &嘗試登錄&); &
& & & & & & & & // 连接服务器 &
& & & & & & & & if (XmppConnection.getInstance().login(username, password)) { &
& & & & & & & & & & Log.i(&TaxiConnectionListener&, &登錄成功&); &
& & & & & & & & } else { &
& & & & & & & & & & Log.i(&TaxiConnectionListener&, &重新登錄&); &
& & & & & & & & & & tExit.schedule(new timetask(), logintime); &
& & & & & & & & } &
& & & & & & } &
& & & & } &
& & @Override &
& & public void reconnectingIn(int arg0) { &
& & @Override &
& & public void reconnectionFailed(Exception arg0) { &
& & @Override &
& & public void reconnectionSuccessful() { &
其次就是给连接设置监听器了,最好放在登录方法里,关闭连接方法里移除监听
// 添加連接監聽 &
TaxiConnectionListener connectionListener = new TaxiConnectionListener(); &
getConnection().addConnectionListener(connectionListener); &
connection.removeConnectionListener(connectionListener); &

我要回帖

更多关于 lol一直掉线 崩溃 的文章

 

随机推荐