File tree Expand file tree Collapse file tree 3 files changed +25
-7
lines changed
src/net/tootallnate/websocket Expand file tree Collapse file tree 3 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -47,9 +47,9 @@ Writing your own WebSocket Client
47
47
48
48
The ` net.tootallnate.websocket.WebSocketClient ` abstract class can connect to
49
49
valid WebSocket servers. The constructor expects a valid ` ws:// ` URI to
50
- connect to. Important events ` onOpen ` , ` onClose ` , and ` onMessage ` get fired
51
- throughout the life of the WebSocketClient, and must be implemented in ** your **
52
- subclass.
50
+ connect to. Important events ` onOpen ` , ` onClose ` , ` onMessage ` and onIOError get
51
+ fired throughout the life of the WebSocketClient, and must be implemented in
52
+ ** your ** subclass.
53
53
54
54
License
55
55
-------
Original file line number Diff line number Diff line change @@ -150,7 +150,7 @@ private boolean tryToConnect(InetSocketAddress remote) {
150
150
client .register (selector , SelectionKey .OP_CONNECT );
151
151
152
152
} catch (IOException ex ) {
153
- ex . printStackTrace ( );
153
+ onIOError ( ex );
154
154
return false ;
155
155
}
156
156
@@ -180,7 +180,7 @@ public void run() {
180
180
}
181
181
}
182
182
} catch (IOException ex ) {
183
- ex . printStackTrace ( );
183
+ onIOError ( ex );
184
184
} catch (NoSuchAlgorithmException ex ) {
185
185
ex .printStackTrace ();
186
186
}
@@ -348,6 +348,15 @@ public void onClose(WebSocket conn) {
348
348
onClose ();
349
349
}
350
350
351
+ /**
352
+ * Triggered on any IOException error. This method should be overridden for custom
353
+ * implementation of error handling (e.g. when network is not available).
354
+ * @param ex
355
+ */
356
+ public void onIOError (IOException ex ) {
357
+ ex .printStackTrace ();
358
+ }
359
+
351
360
// ABTRACT METHODS /////////////////////////////////////////////////////////
352
361
public abstract void onMessage (String message );
353
362
public abstract void onOpen ();
Original file line number Diff line number Diff line change @@ -196,7 +196,7 @@ public void run() {
196
196
selector = Selector .open ();
197
197
server .register (selector , server .validOps ());
198
198
} catch (IOException ex ) {
199
- ex . printStackTrace ( );
199
+ onIOError ( ex );
200
200
return ;
201
201
}
202
202
@@ -250,7 +250,7 @@ public void run() {
250
250
}
251
251
}
252
252
} catch (IOException ex ) {
253
- ex . printStackTrace ( );
253
+ onIOError ( ex );
254
254
} catch (RuntimeException ex ) {
255
255
ex .printStackTrace ();
256
256
} catch (NoSuchAlgorithmException ex ) {
@@ -415,6 +415,15 @@ public void onClose(WebSocket conn) {
415
415
}
416
416
}
417
417
418
+ /**
419
+ * Triggered on any IOException error. This method should be overridden for custom
420
+ * implementation of error handling (e.g. when network is not available).
421
+ * @param ex
422
+ */
423
+ public void onIOError (IOException ex ) {
424
+ ex .printStackTrace ();
425
+ }
426
+
418
427
private byte [] getPart (String key ) {
419
428
long keyNumber = Long .parseLong (key .replaceAll ("[^0-9]" ,"" ));
420
429
long keySpace = key .split ("\u0020 " ).length - 1 ;
You can’t perform that action at this time.
0 commit comments