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


  • Building a connection first, can pass multiple different params to it for logging and other features
let connection = new SignalR.HubConnectionBuilder()
.withUrl('', {
accessTokenFactory: () => token
  • Starting the connection
.then(() => {
console.log('SignalR: STARTED!@!#!@#!@#!')
setInterval((): void => {
if (connection.state) {
}, 15000)
.catch(err => console.log('Error while establishing connection :(', err))
  • Listening to events sent from server SignalR uses the on method to listen to methods coming from server and off method to close the connection
connection.on('messageReceived', (data: any) => {
})'messageReceived', c => {
console.log('messageRecieved Off', c)
  • 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

connection.onclose((error: any) => {
console.log('Connection closed', JSON.stringify(error))