Skip to content

Commit 1759d61

Browse files
committed
fixed TooTallNate#127: CancelledKeyException when WiFi is disconnected
1 parent b967cba commit 1759d61

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/main/java/org/java_websocket/client/WebSocketClient.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,12 @@ public final void onWebsocketError( WebSocket conn, Exception ex ) {
386386

387387
@Override
388388
public final void onWriteDemand( WebSocket conn ) {
389-
key.interestOps( SelectionKey.OP_READ | SelectionKey.OP_WRITE );
390-
selector.wakeup();
389+
try {
390+
key.interestOps( SelectionKey.OP_READ | SelectionKey.OP_WRITE );
391+
selector.wakeup();
392+
} catch ( CancelledKeyException e ) {
393+
// since such an exception/event will also occur on the selector there is no need to do anything here
394+
}
391395
}
392396

393397
public WebSocket getConnection() {

0 commit comments

Comments
 (0)