javascript - Android WebSocket - disconnection detection strange behaviour -
this first question here in stackoverflow after years use :d
i'm working on application use tooltallnate api. find small issue while trying detect disconnection due line problem (like low signal; in situation simulate line problem deactivating local network ).
after digging in documentation, found 2 different situations:
1) manually close
when close websocket on own (so not due line problem) application flow this
- call
close()method defined on websocketclient.java this method call
close()method of websocketimpl.java@override public void close( int code, string message ) { engine.close( code, message ); }in method
close( int code, string message, boolean remote ) {*code*},abnormal,normalclose cases divided seems important part more or less samereadystate setted **readystate.closing** readystate = readystate.closing;in websocketclient class there running thread ( start on websocket connection ) there while loop check readystate value
try { while ( !isclosing() && !isclosed() && ( readbytes = istream.read( rawbuffer ) ) != -1 ) { engine.decode( bytebuffer.wrap( rawbuffer, 0, readbytes ) ); } engine.eot();when readystate setted closing condition application call
eot();method connection close , through closeconnection() method onwebsocketclose() method called , thread interrupted , , important ,stopconnectionlosttimer()called ; timer used check connection state using classic ping/pong method
so seem work perfectly
line network problem disconnection
to test situation deactivate local network (where i'm testing application ) simulate problem on line.
the program flow same in situation close method called in startconnectionlosttimer() if there delay on server response call close() method abnormal_close condition
also condition close method set readystate = readystate.closing; seems thread there while loop checking state waiting , eot method ( close connection , stop connection lost timer ) never called , timer never stopped.
i tried override onclosing() method , call stopconnectionlosttimer() method again nothing happen because seems stuck...
another strange beehaviour ( or form me ) when reactivate local network goes through eot method close , stop everything...
so expecting after connection lost timeout has work normal manually close()...
where i'm wrong ?? ( because know there error on argument :d )
edit: hello, found important thing reason why while statement blocked long time before can close connection; in while statement there condition
( readbytes = istream.read( rawbuffer ) ) and function after 2 minutes catch exception "no route no host" . suppose after sort of timeout ( can't find ) call exception , connection closed
finally found way manage timeout ; in standard implementation can't set timeout input stream read method create own websocketclient class , when socket created , set timemout setsotimeout
socket = new socket( proxy ); socket.setsotimeout(20000); //for 20 second of timeout ; it's in millisecond
Comments
Post a Comment