Simply put, this kind of code will throw NullPointerException at com.microsoft.signalr.HubConnection$ConnectionState.getNextInvocationId()
The reason behind is rather easy to understand, it must be because the connection hasn't been established yet after the call hubConnection.start();
But knowing the cause didn't help me to find out how to achieve my intention.
I can see that the start() method returns a Completable object. That object has many rather suspicious methods like doOnComplete(), andThen(), etc...
I tried to figure out how to use it but there was no hope.
So, simply put, how to invoke a method immediately after HubConnection.start() in Java?
After about an hour more kept trying in the hopeless, I finally can achieve my goal, so I will write it down here in case there is anyone might need it in the future.
This will make the chatHubConnection.invoke(Void.class, "GetConnectionId") run right after the connection establishes.
Right now I can only think of this solution, but looks like its not a good approach as I make it blocked...
EDIT: I am using ASP.NET Core SignalR. I use SignalR for my Android application. And I implemented the version 1.0.0 as showed in this tutorial ASP.NET Core SignalR
Java client And from out of no where, today I encountered another exception, even when I just only write "chatHubConnection.start()". The issue is described in this link [SignalR] Java Client NullPointerException
As the hint solution in the above issue, I have implemented the latest version of SignalR, that is 3.0.0-preview-19075-0444. And then, the problem's gone.
After implementing the lastest version, I tried writing the code that threw exception yesterday:
This time, it still threw exception, but it described the error in a more detail, it said: "The 'invoke' method cannot be called if the connection is not active.". Very good :)
Then, I tried writing the line of code that I thought it should have worked yesterday:
Are you using ASP.NET SignalR? or ASP.NET Core SignalR? If possible, please tell us which SignalR Java client package you are using to setup client application.
With Regards,
Fei Han
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Are you using ASP.NET SignalR? or ASP.NET Core SignalR? If possible, please tell us which SignalR Java client package you are using to setup client application.
None
0 Points
3 Posts
SignalR Java client - How to invoke a method immediately after hub.start()?
May 06, 2019 03:16 AM|daophilac|LINK
Simply put, this kind of code will throw NullPointerException at com.microsoft.signalr.HubConnection$ConnectionState.getNextInvocationId()
The reason behind is rather easy to understand, it must be because the connection hasn't been established yet after the call hubConnection.start();
But knowing the cause didn't help me to find out how to achieve my intention.
I can see that the start() method returns a Completable object. That object has many rather suspicious methods like doOnComplete(), andThen(), etc...
I tried to figure out how to use it but there was no hope.
So, simply put, how to invoke a method immediately after HubConnection.start() in Java?
None
0 Points
3 Posts
Re: SignalR Java client - How to invoke a method immediately after hub.start()?
May 06, 2019 03:56 AM|daophilac|LINK
After about an hour more kept trying in the hopeless, I finally can achieve my goal, so I will write it down here in case there is anyone might need it in the future.
This will make the chatHubConnection.invoke(Void.class, "GetConnectionId") run right after the connection establishes.
Right now I can only think of this solution, but looks like its not a good approach as I make it blocked...
EDIT:
I am using ASP.NET Core SignalR. I use SignalR for my Android application. And I implemented the version 1.0.0 as showed in this tutorial ASP.NET Core SignalR Java client
And from out of no where, today I encountered another exception, even when I just only write "chatHubConnection.start()". The issue is described in this link [SignalR] Java Client NullPointerException
As the hint solution in the above issue, I have implemented the latest version of SignalR, that is 3.0.0-preview-19075-0444. And then, the problem's gone.
After implementing the lastest version, I tried writing the code that threw exception yesterday:
This time, it still threw exception, but it described the error in a more detail, it said: "The 'invoke' method cannot be called if the connection is not active.". Very good :)
Then, I tried writing the line of code that I thought it should have worked yesterday:
And guess what? It actually works. That makes a whole sense and beautiful too.
All-Star
40565 Points
6233 Posts
Microsoft
Re: SignalR Java client - How to invoke a method immediately after hub.start()?
May 06, 2019 06:58 AM|Fei Han - MSFT|LINK
Hi daophilac,
Welcome to ASP.NET forums.
Are you using ASP.NET SignalR? or ASP.NET Core SignalR? If possible, please tell us which SignalR Java client package you are using to setup client application.
With Regards,
Fei Han
None
0 Points
3 Posts
Re: SignalR Java client - How to invoke a method immediately after hub.start()?
May 08, 2019 06:12 PM|daophilac|LINK
Hi, please see my edited answer