File tree Expand file tree Collapse file tree 2 files changed +47
-12
lines changed
src/net/tootallnate/websocket Expand file tree Collapse file tree 2 files changed +47
-12
lines changed Original file line number Diff line number Diff line change 14
14
import java .util .Set ;
15
15
import java .util .concurrent .LinkedBlockingQueue ;
16
16
17
+ import android .util .Log ;
18
+
17
19
/**
18
20
* The <tt>WebSocketClient</tt> is an abstract class that expects a valid
19
21
* "ws://" URI to connect to. When connected, an instance recieves important
@@ -116,12 +118,16 @@ public void connect() {
116
118
* closes the socket connection, and ends the client socket thread.
117
119
* @throws IOException When socket related I/O errors occur.
118
120
*/
119
- public void close () throws IOException {
120
- if (running ) {
121
- this .running = false ;
122
- selector .wakeup ();
123
- conn .close ();
124
- }
121
+ public void close () throws IOException
122
+ {
123
+ Boolean active = running ;
124
+ this .running = false ;
125
+
126
+ if (active )
127
+ {
128
+ selector .wakeup ();
129
+ conn .close ();
130
+ }
125
131
}
126
132
127
133
/**
@@ -344,17 +350,36 @@ public void onOpen(WebSocket conn) {
344
350
* Calls subclass' implementation of <var>onClose</var>.
345
351
* @param conn
346
352
*/
347
- public void onClose (WebSocket conn ) {
348
- onClose ();
353
+ public void onClose (WebSocket conn )
354
+ {
355
+ try
356
+ {
357
+ close ();
358
+ }
359
+ catch (IOException ex )
360
+ {
361
+ onIOError (ex );
362
+ }
363
+ onClose ();
349
364
}
350
365
351
366
/**
352
367
* Triggered on any IOException error. This method should be overridden for custom
353
368
* implementation of error handling (e.g. when network is not available).
354
369
* @param ex
355
370
*/
356
- public void onIOError (IOException ex ) {
371
+ public void onIOError (IOException ex )
372
+ {
357
373
ex .printStackTrace ();
374
+
375
+ try
376
+ {
377
+ this .close ();
378
+ }
379
+ catch (IOException e )
380
+ {
381
+ onIOError (ex );
382
+ }
358
383
}
359
384
360
385
// ABTRACT METHODS /////////////////////////////////////////////////////////
Original file line number Diff line number Diff line change @@ -420,9 +420,19 @@ public void onClose(WebSocket conn) {
420
420
* implementation of error handling (e.g. when network is not available).
421
421
* @param ex
422
422
*/
423
- public void onIOError (IOException ex ) {
424
- ex .printStackTrace ();
425
- }
423
+ public void onIOError (IOException ex )
424
+ {
425
+ ex .printStackTrace ();
426
+
427
+ try
428
+ {
429
+ this .stop ();
430
+ }
431
+ catch (IOException e )
432
+ {
433
+ onIOError (ex );
434
+ }
435
+ }
426
436
427
437
private byte [] getPart (String key ) {
428
438
long keyNumber = Long .parseLong (key .replaceAll ("[^0-9]" ,"" ));
You can’t perform that action at this time.
0 commit comments