Skip to content

Commit 710eefd

Browse files
committed
ws client fix
1 parent 002ad9b commit 710eefd

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/org/java_websocket/client/WebSocketClient.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@
55
import java.net.Socket;
66
import java.net.URI;
77
import java.nio.ByteBuffer;
8-
import java.nio.channels.ClosedByInterruptException;
9-
import java.nio.channels.NotYetConnectedException;
10-
import java.nio.channels.SelectionKey;
11-
import java.nio.channels.Selector;
12-
import java.nio.channels.SocketChannel;
13-
import java.nio.channels.UnresolvedAddressException;
8+
import java.nio.channels.*;
149
import java.util.Iterator;
1510
import java.util.List;
1611
import java.util.Map;
@@ -257,6 +252,10 @@ private final void interruptableRun() {
257252
} catch ( IOException e ) {
258253
onError( e );
259254
conn.close( CloseFrame.ABNORMAL_CLOSE );
255+
} catch ( CancelledKeyException e ) {
256+
// remote peer closed the channel abnormally, probably caused by server crash or network issue
257+
onError( e );
258+
conn.close( CloseFrame.ABNORMAL_CLOSE );
260259
} catch ( RuntimeException e ) {
261260
// this catch case covers internal errors only and indicates a bug in this websocket implementation
262261
onError( e );
@@ -312,6 +311,9 @@ private void sendHandshake() throws IOException , InvalidHandshakeException , In
312311
* @return Returns '0 = CONNECTING', '1 = OPEN', '2 = CLOSING' or '3 = CLOSED'
313312
*/
314313
public int getReadyState() {
314+
if (conn == null) {
315+
return WebSocket.READY_STATE_CONNECTING;
316+
}
315317
return conn.getReadyState();
316318
}
317319

0 commit comments

Comments
 (0)