diff --git a/src/main/java/io/deepstream/Connection.java b/src/main/java/io/deepstream/Connection.java index 15acc07..577429d 100644 --- a/src/main/java/io/deepstream/Connection.java +++ b/src/main/java/io/deepstream/Connection.java @@ -398,7 +398,7 @@ private void tryReconnect() { int maxReconnectInterval = options.getMaxReconnectInterval(); if( this.reconnectionAttempt < maxReconnectAttempts ) { - if(this.globalConnectivityState == GlobalConnectivityState.CONNECTED) { + if(this.globalConnectivityState == GlobalConnectivityState.DISCONNECTED) { this.setState(ConnectionState.RECONNECTING); this.reconnectTimeout = new Timer(); this.reconnectTimeout.schedule(new TimerTask() { diff --git a/src/main/java/io/deepstream/DeepstreamClientAbstract.java b/src/main/java/io/deepstream/DeepstreamClientAbstract.java index e1fd622..5bca2cb 100644 --- a/src/main/java/io/deepstream/DeepstreamClientAbstract.java +++ b/src/main/java/io/deepstream/DeepstreamClientAbstract.java @@ -45,11 +45,13 @@ void onError(Topic topic, Event event, String msg) throws DeepstreamException { * Help to diagnose the problem quicker by checking for * some mon problems */ - if( event.equals( Event.ACK_TIMEOUT ) || event.equals( Event.RESPONSE_TIMEOUT ) ) { - if( getConnectionState().equals( ConnectionState.AWAITING_AUTHENTICATION ) ) { - String errMsg = "Your message timed out because you\'re not authenticated. Have you called login()?"; - onError( Topic.ERROR, Event.NOT_AUTHENTICATED, errMsg ); - return; + if (event != null) { + if( event.equals( Event.ACK_TIMEOUT ) || event.equals( Event.RESPONSE_TIMEOUT ) ) { + if( getConnectionState().equals( ConnectionState.AWAITING_AUTHENTICATION ) ) { + String errMsg = "Your message timed out because you\'re not authenticated. Have you called login()?"; + onError(Topic.ERROR, Event.NOT_AUTHENTICATED, errMsg); + return; + } } } diff --git a/src/main/java/io/deepstream/JavaEndpointWebsocket.java b/src/main/java/io/deepstream/JavaEndpointWebsocket.java index f4cc7bf..088d9f6 100644 --- a/src/main/java/io/deepstream/JavaEndpointWebsocket.java +++ b/src/main/java/io/deepstream/JavaEndpointWebsocket.java @@ -26,7 +26,9 @@ class JavaEndpointWebsocket implements Endpoint { @Override public void send(String message) { - this.websocket.send( message ); + if (this.websocket.isOpen()) { + this.websocket.send(message); + } } @Override