SignalR
SignalR is a WebSockets implementation for dotnet applications. I used the frontend client for this which was @aspnet/signalr, this version is for dotnet core 2.0 and the version for 3.0 is @microsoft/signalr
#
Basics- Building a connection first, can pass multiple different params to it for logging and other features
- Starting the connection
- Listening to events sent from server
SignalR uses the
on
method to listen to methods coming from server andoff
method to close the connection
- Sending events to server
SignalR uses the
invoke
method to call methods on the server,
A simple way to keep the server alive is sending a heartbeat
Wrapping this in an interval and calling it constantly would do the trick (code above in starting a connection)
|| Note: in the 3.0 version a simple .withAutomaticReconnect()
can be passed in the HubConnectionBuilder()
chain and it would do. -- Ref
- Callback if connection closes
For running any processes and logging errors if the connection drops, there's a onclose
method
#
Referrences- https://docs.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/handling-connection-lifetime-events#signalrvstransport
- https://www.jerriepelser.com/blog/automatic-reconnects-signalr/
- https://docs.microsoft.com/en-us/javascript/api/@aspnet/signalr/hubconnection?view=signalr-js-latest#on
- https://docs.microsoft.com/en-us/aspnet/core/signalr/configuration?view=aspnetcore-3.0&tabs=dotnet
- https://docs.microsoft.com/en-us/aspnet/core/signalr/introduction?view=aspnetcore-3.0