Skip to main content
Version: 7.1.2

SignalR

SignalR is a very popular real-time communication library from Microsoft, especially within .NET framework. It is also available as a JavaScript client. This allows JavaScript applications to connect to data sources originating from various .NET frameworks very easily.

Here's how it looks from JavaScript side:

const connection = new signalR.HubConnectionBuilder()
.withUrl('/chart')
.withAutomaticReconnect()
.configureLogging(signalR.LogLevel.Information)
.build()

async function start() {
try {
await connection.start()
console.log("SignalR Connected.")
} catch (err) {
console.log(err)
setTimeout(start, 5000)
}
};
start()

connection.on('add', (newDataPoints) => {
// newDataPoints: { x: number, y: number }[]
lineSeries.appendJSON(newDataPoints)
})

And an extract from ASP .NET Core example on the server side:

public struct DataPointXY
{
public double X { get; set; }
public double Y { get; set; }
public DataPointXY(double x, double y)
{
X = x;
Y = y;
}
}
...
DataPointXY[] dataPointArr = new DataPointXY[] { new DataPointXY(timestamp, measurement) };
await _hub.Clients.All.SendAsync(
"add",
dataPointArr,
cancellationToken: stoppingToken
);

Other topics that are closely related to handling real-time data: