NaikSoftware / StompProtocolAndroid

STOMP protocol via WebSocket for Android
MIT License
597 stars 265 forks source link

WebsocketNotConnectedException #119

Open dvasea1 opened 6 years ago

dvasea1 commented 6 years ago

Can explain me the problem please:

org.java_websocket.WebSocketImpl.send (WebSocketImpl.java:598)

  | org.java_websocket.WebSocketImpl.sendFrame (WebSocketImpl.java:624)   | org.java_websocket.WebSocketImpl.sendPing (WebSocketImpl.java:631)   | org.java_websocket.AbstractWebSocket$1.run (AbstractWebSocket.java:142)   | java.util.TimerThread.mainLoop (Timer.java:555)   | java.util.TimerThread.run (Timer.java:505)

forresthopkinsa commented 6 years ago

Try again.

Include information like how you encountered the error, what your code looks like, maybe even the exception itself would be nice...

stfbee commented 5 years ago

@forresthopkinsa i have the same error 😢 How to reproduce: try to connect to host without websocket log:

2019-02-14 11:57:23.378 29646-29646/ru.stfbee.offline E/NetworkModule: ~~~~~ LifecycleEvent.Type.ERROR EVENT ~~~~~
    java.net.ConnectException: failed to connect to /10.10.10.12 (port 8090) from /:: (port 34364): connect failed: ECONNREFUSED (Connection refused)
        at libcore.io.IoBridge.connect(IoBridge.java:138)
        at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:129)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:356)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
        at java.net.Socket.connect(Socket.java:616)
        at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:247)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: android.system.ErrnoException: connect failed: ECONNREFUSED (Connection refused)
        at libcore.io.Linux.connect(Native Method)
        at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:126)
        at libcore.io.IoBridge.connectErrno(IoBridge.java:152)
        at libcore.io.IoBridge.connect(IoBridge.java:130)
        at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:129) 
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:356) 
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) 
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) 
        at java.net.Socket.connect(Socket.java:616) 
        at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:247) 
        at java.lang.Thread.run(Thread.java:764) 
ru.stfbee.offline D/NetworkModule: ~~~~~ LifecycleEvent.Type.CLOSED EVENT ~~~~~
ru.stfbee.offline W/System.err: io.reactivex.exceptions.OnErrorNotImplementedException: The exception was not handled due to missing onError handler in the subscribe() method call. Further reading: https://github.com/ReactiveX/RxJava/wiki/Error-Handling | org.java_websocket.exceptions.WebsocketNotConnectedException
ru.stfbee.offline W/System.err:     at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:704)
ru.stfbee.offline W/System.err:     at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:701)
ru.stfbee.offline W/System.err:     at io.reactivex.internal.subscribers.LambdaSubscriber.onError(LambdaSubscriber.java:79)
ru.stfbee.offline W/System.err:     at io.reactivex.internal.operators.flowable.FlowableObserveOn$BaseObserveOnSubscriber.checkTerminated(FlowableObserveOn.java:209)
ru.stfbee.offline W/System.err:     at io.reactivex.internal.operators.flowable.FlowableObserveOn$ObserveOnSubscriber.runAsync(FlowableObserveOn.java:399)
ru.stfbee.offline W/System.err:     at io.reactivex.internal.operators.flowable.FlowableObserveOn$BaseObserveOnSubscriber.run(FlowableObserveOn.java:176)
ru.stfbee.offline W/System.err:     at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:119)
ru.stfbee.offline W/System.err:     at android.os.Handler.handleCallback(Unknown Source:2)
ru.stfbee.offline W/System.err:     at android.os.Handler.dispatchMessage(Unknown Source:4)
ru.stfbee.offline W/System.err:     at android.os.Looper.loop(Unknown Source:139)
ru.stfbee.offline W/System.err:     at android.app.ActivityThread.main(Unknown Source:65)
ru.stfbee.offline W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
ru.stfbee.offline W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(Unknown Source:11)
ru.stfbee.offline W/System.err:     at com.android.internal.os.ZygoteInit.main(Unknown Source:338)
ru.stfbee.offline W/System.err: Caused by: org.java_websocket.exceptions.WebsocketNotConnectedException
ru.stfbee.offline W/System.err:     at org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:598)
ru.stfbee.offline W/System.err:     at org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:575)
ru.stfbee.offline W/System.err:     at org.java_websocket.client.WebSocketClient.send(WebSocketClient.java:207)
ru.stfbee.offline W/System.err:     at ua.naiksoftware.stomp.provider.WebSocketsConnectionProvider.rawSend(WebSocketsConnectionProvider.java:126)
ru.stfbee.offline W/System.err:     at ua.naiksoftware.stomp.provider.AbstractConnectionProvider.lambda$send$0(AbstractConnectionProvider.java:80)
ru.stfbee.offline W/System.err:     at ua.naiksoftware.stomp.provider.-$$Lambda$AbstractConnectionProvider$YT0nnX9-2PEI5qobethPTKDOT_o.call(Unknown Source:4)
ru.stfbee.offline W/System.err:     at io.reactivex.internal.operators.completable.CompletableFromCallable.subscribeActual(CompletableFromCallable.java:36)
ru.stfbee.offline W/System.err:     at io.reactivex.Completable.subscribe(Completable.java:2302)
ru.stfbee.offline W/System.err:     at io.reactivex.internal.operators.completable.CompletableConcatArray$ConcatInnerObserver.next(CompletableConcatArray.java:89)
ru.stfbee.offline W/System.err:     at io.reactivex.internal.operators.completable.CompletableConcatArray$ConcatInnerObserver.onComplete(CompletableConcatArray.java:65)
ru.stfbee.offline W/System.err:     at io.reactivex.internal.operators.maybe.MaybeIgnoreElementCompletable$IgnoreMaybeObserver.onComplete(MaybeIgnoreElementCompletable.java:79)
ru.stfbee.offline W/System.err:     at io.reactivex.internal.operators.observable.ObservableElementAtMaybe$ElementAtObserver.onComplete(ObservableElementAtMaybe.java:102)
ru.stfbee.offline W/System.err:     at io.reactivex.internal.observers.BasicFuseableObserver.onComplete(BasicFuseableObserver.java:119)
ru.stfbee.offline W/System.err:     at io.reactivex.internal.util.NotificationLite.accept(NotificationLite.java:239)
ru.stfbee.offline W/System.err:     at io.reactivex.subjects.BehaviorSubject$BehaviorDisposable.test(BehaviorSubject.java:569)
ru.stfbee.offline W/System.err:     at io.reactivex.subjects.BehaviorSubject$BehaviorDisposable.emitNext(BehaviorSubject.java:564)
ru.stfbee.offline W/System.err:     at io.reactivex.subjects.BehaviorSubject.onComplete(BehaviorSubject.java:292)
ru.stfbee.offline W/System.err:     at ua.naiksoftware.stomp.StompClient.lambda$disconnectCompletable$11(StompClient.java:228)
ru.stfbee.offline W/System.err:     at ua.naiksoftware.stomp.-$$Lambda$StompClient$MTAxMUXu502JN_KwRbV66EvBJpI.run(Unknown Source:2)
ru.stfbee.offline W/System.err:     at io.reactivex.internal.operators.completable.CompletableDoFinally$DoFinallyObserver.runFinally(CompletableDoFinally.java:96)
ru.stfbee.offline W/System.err:     at io.reactivex.internal.operators.completable.CompletableDoFinally$DoFinallyObserver.onError(CompletableDoFinally.java:73)
ru.stfbee.offline W/System.err:     at io.reactivex.internal.operators.completable.CompletableFromAction.subscribeActual(CompletableFromAction.java:38)
ru.stfbee.offline W/System.err:     at io.reactivex.Completable.subscribe(Completable.java:2302)
ru.stfbee.offline W/System.err:     at io.reactivex.internal.operators.completable.CompletableDoFinally.subscribeActual(CompletableDoFinally.java:43)
ru.stfbee.offline W/System.err:     at io.reactivex.Completable.subscribe(Completable.java:2302)
ru.stfbee.offline W/System.err:     at io.reactivex.Completable.subscribe(Completable.java:2376)
ru.stfbee.offline W/System.err:     at ua.naiksoftware.stomp.StompClient.disconnect(StompClient.java:210)
ru.stfbee.offline W/System.err:     at ua.naiksoftware.stomp.StompClient.lambda$connect$2(StompClient.java:129)
ru.stfbee.offline W/System.err:     at ua.naiksoftware.stomp.-$$Lambda$StompClient$vVcYMb21o9E34jwNPpF11oh0iG4.accept(Unknown Source:6)
ru.stfbee.offline W/System.err:     at io.reactivex.internal.observers.LambdaObserver.onNext(LambdaObserver.java:63)
ru.stfbee.offline W/System.err:     at io.reactivex.subjects.PublishSubject$PublishDisposable.onNext(PublishSubject.java:308)
ru.stfbee.offline W/System.err:     at io.reactivex.subjects.PublishSubject.onNext(PublishSubject.java:228)
ru.stfbee.offline W/System.err:     at ua.naiksoftware.stomp.provider.AbstractConnectionProvider.emitLifecycleEvent(AbstractConnectionProvider.java:112)
ru.stfbee.offline W/System.err:     at ua.naiksoftware.stomp.provider.WebSocketsConnectionProvider$1.onClose(WebSocketsConnectionProvider.java:96)
ru.stfbee.offline W/System.err:     at org.java_websocket.client.WebSocketClient.onWebsocketClose(WebSocketClient.java:373)
ru.stfbee.offline W/System.err:     at org.java_websocket.WebSocketImpl.closeConnection(WebSocketImpl.java:493)
ru.stfbee.offline W/System.err:     at org.java_websocket.WebSocketImpl.closeConnection(WebSocketImpl.java:516)
ru.stfbee.offline W/System.err:     at org.java_websocket.client.WebSocketClient.run(WebSocketClient.java:265)
ru.stfbee.offline W/System.err:     at java.lang.Thread.run(Thread.java:764)
? W/ActivityManager:   Force finishing activity ru.stfbee.offline/ru.stfbee.authentication.AuthenticationActivity
? W/ActivityManager:   Force finishing activity ru.stfbee.offline/ru.stfbee.authentication.LoginActivity
? W/ActivityManager: Activity pause timeout for ActivityRecord{31c211d u0 ru.stfbee.offline/ru.stfbee.authentication.AuthenticationActivity t234 f}
? W/ActivityManager: Activity destroy timeout for ActivityRecord{31c211d u0 ru.stfbee.offline/ru.stfbee.authentication.AuthenticationActivity t234 f}
? W/ActivityManager: Activity destroy timeout for ActivityRecord{8d44212 u0 ru.stfbee.offline/ru.stfbee.authentication.LoginActivity t234 f}
? E/BufferQueueProducer: [ru.stfbee.offline/ru.stfbee.authentication.LoginActivity#0] queueBuffer: BufferQueue has been abandoned
ru.stfbee.offline E/Surface: queueBuffer: error queuing buffer to SurfaceTexture, -19
ru.stfbee.offline I/Adreno: QueueBuffer: queueBuffer failed
ru.stfbee.offline W/OpenGLRenderer: swapBuffers encountered EGL error 12301 on 0x721136d580, halting rendering...
? D/PowerKeeper.Event: notifyActiveKilled processName: ru.stfbee.offline, pid:29646, reason:crash

This is my code:

val stompClient = Stomp.over(Stomp.ConnectionProvider.OKHTTP, "ws://${Config.IP}:${Config.PORT}/hello")
stompClient.lifecycle()
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe({
            if (it.type != null) {
                when (it.type!!) {
                    LifecycleEvent.Type.OPENED -> Log.d(TAG, "Stomp connection opened")
                    LifecycleEvent.Type.ERROR -> {
                        Log.e(TAG, "~~~~~ LifecycleEvent.Type.ERROR EVENT ~~~~~", it.exception)
                    }
                    LifecycleEvent.Type.CLOSED -> {
                        Log.d(TAG, "~~~~~ LifecycleEvent.Type.CLOSED EVENT ~~~~~")
                    }
                    LifecycleEvent.Type.FAILED_SERVER_HEARTBEAT -> {
                        Log.d(TAG, "пинг потерян, повторяю, ПИНГ ПОТЕРЯН!!1")
                    }
                }
            }
        }, {
            Log.e(TAG, "onError", it)
        })

stompClient.connect()

App crashes without any code links, onError callback is ignored, try{} doesn't help

NaikSoftware commented 5 years ago

Thanks for detailed information!

stfbee commented 5 years ago

Well, i found how to fix:

I forgot to add an onError callback to the stompClient.topic().subscribe() method.

NaikSoftware commented 5 years ago

Yes, if you have any subscribtions to topics or sending messagess, you must implement onError callback for handling connection errors or other exceptions.