3

how to identify when java client connected successfully to SignalR. where is onConnect life cycle .

i want to do something when hubConnection connected to server.

hubConnection have onClose method for subscribing callback method that run when connection is closed or disconnected.

Ahmad Hamzavi
  • 626
  • 6
  • 18

2 Answers2

3

BrennanConroy Answer:

When start returns then you know the connection was successful.

For example you could do:

hubConnection.start().doOnComplete(() -> logger.info("Client connected successfully."));

https://github.com/aspnet/AspNetCore.Docs/issues/12122#issuecomment-485851457

Ahmad Hamzavi
  • 626
  • 6
  • 18
2

I tried doOnComplete() and this solution not working for me. IDE shows "The result of doOnComplete is not used". I found better solution:

connection.start().subscribe(new CompletableObserver() {
        @Override
        public void onSubscribe(@NonNull Disposable d) {}

        @Override
        public void onError(@NonNull Throwable e) {
            // TODO OnError
        }

        @Override
        public void onComplete() {
            Log.d("SocketSrv","Connected");
        }

    });