Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to determine whether the current socket is connecting state #190

Open
Mukesh1507 opened this issue Oct 24, 2020 · 0 comments
Open

How to determine whether the current socket is connecting state #190

Mukesh1507 opened this issue Oct 24, 2020 · 0 comments

Comments

@Mukesh1507
Copy link

Mukesh1507 commented Oct 24, 2020

How to detected that socket is connecting.
After refer #109.
Variables are not declare in StompClient.

I have try make connection from two places. It go to connect for two times. I have received 2 times connected event. It start separate queue for connection on mStompClient.connect(). After fewseconds it crash.

Crash
ua.naiksoftware.stomp.provider.AbstractConnectionProvider.lambda$send$0 AbstractConnectionProvider.java:79
ua.naiksoftware.stomp.provider.-$$Lambda$AbstractConnectionProvider$YT0nnX9-2PEI5qobethPTKDOT_o.call Unknown Source:4
io.reactivex.internal.operators.completable.CompletableFromCallable.subscribeActual CompletableFromCallable.java:36
io.reactivex.Completable.subscribe Completable.java:2301
io.reactivex.internal.operators.completable.CompletableConcatArray$ConcatInnerObserver.next CompletableConcatArray.java:89
io.reactivex.internal.operators.completable.CompletableConcatArray$ConcatInnerObserver.onComplete CompletableConcatArray.java:65
io.reactivex.internal.operators.maybe.MaybeIgnoreElementCompletable$IgnoreMaybeObserver.onComplete MaybeIgnoreElementCompletable.java:79
io.reactivex.internal.operators.observable.ObservableElementAtMaybe$ElementAtObserver.onComplete ObservableElementAtMaybe.java:102
io.reactivex.internal.observers.BasicFuseableObserver.onComplete BasicFuseableObserver.java:119
io.reactivex.internal.util.NotificationLite.accept NotificationLite.java:239
io.reactivex.subjects.BehaviorSubject$BehaviorDisposable.test BehaviorSubject.java:569
io.reactivex.subjects.BehaviorSubject$BehaviorDisposable.emitNext BehaviorSubject.java:564
io.reactivex.subjects.BehaviorSubject.onComplete BehaviorSubject.java:292
ua.naiksoftware.stomp.StompClient.lambda$disconnectCompletable$12 StompClient.java:232
ua.naiksoftware.stomp.-$$Lambda$StompClient$kVxuI7X9rCmrMqSYYxig5SXBJ2U.run Unknown Source:2
io.reactivex.internal.operators.completable.CompletableDoFinally$DoFinallyObserver.runFinally CompletableDoFinally.java:96
io.reactivex.internal.operators.completable.CompletableDoFinally$DoFinallyObserver.onComplete CompletableDoFinally.java:79
io.reactivex.internal.operators.completable.CompletableFromAction.subscribeActual CompletableFromAction.java:43
io.reactivex.Completable.subscribe Completable.java:2301
io.reactivex.internal.operators.completable.CompletableDoFinally.subscribeActual CompletableDoFinally.java:43
io.reactivex.Completable.subscribe Completable.java:2301
io.reactivex.Completable.subscribe Completable.java:2375
ua.naiksoftware.stomp.StompClient.disconnect StompClient.java:214
ua.naiksoftware.stomp.StompClient.lambda$connect$2 StompClient.java:131
ua.naiksoftware.stomp.-$$Lambda$StompClient$vVcYMb21o9E34jwNPpF11oh0iG4.accept Unknown Source:6
io.reactivex.internal.observers.LambdaObserver.onNext LambdaObserver.java:63
io.reactivex.subjects.PublishSubject$PublishDisposable.onNext PublishSubject.java:308
io.reactivex.subjects.PublishSubject.onNext PublishSubject.java:228
ua.naiksoftware.stomp.provider.AbstractConnectionProvider.emitLifecycleEvent AbstractConnectionProvider.java:114
ua.naiksoftware.stomp.provider.OkHttpConnectionProvider$1.onFailure OkHttpConnectionProvider.java:88
okhttp3.internal.ws.RealWebSocket.failWebSocket RealWebSocket.java:571
okhttp3.internal.ws.RealWebSocket$2.onFailure RealWebSocket.java:221
okhttp3.RealCall$AsyncCall.execute RealCall.java:215
okhttp3.internal.NamedRunnable.run NamedRunnable.java:32
java.util.concurrent.ThreadPoolExecutor.runWorker ThreadPoolExecutor.java:1167

1. Request for Connection
if (!mStompClient.isConnected)
connectToWebSocket()

      fun connectToWebSocket() {
       resetSubscriptions()
      val dispLifecycle = mStompClient.lifecycle()
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe { lifecycleEvent: LifecycleEvent ->
            when (lifecycleEvent.type) {

                LifecycleEvent.Type.OPENED -> {
                    // "Stomp connection opened"
                    Log.v("WebSocket", "Connected")
                    _webSocketStatus.value = Event(true)
                }
                LifecycleEvent.Type.ERROR -> {

                }
                LifecycleEvent.Type.CLOSED -> {
                    //"Stomp connection closed"
                }
                LifecycleEvent.Type.FAILED_SERVER_HEARTBEAT -> {
                    //"Stomp failed server heartbeat"
                }
                else -> {
                    //stomp event ype null
                }
            }
        }
        compositeDisposable.add(dispLifecycle)
        mStompClient.connect()

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant