What is SignalR and why is it needed?
\n\nSignalR is a library for ASP.NET Core that simplifies adding real-time features to web applications. It allows the server to instantly send data to connected clients (browsers, mobile applications, desktop applications) without the need for constant requests from the client.
\n\nWhy is this needed? The traditional HTTP protocol works on a "request-response" principle: the client sends a request, the server responds. To receive updates, the client must constantly poll the server (polling). This is inefficient and creates delays. SignalR solves this problem by providing a persistent two-way connection.
\n\nMain use cases:
\n- \n
- Chats and messengers (instant message delivery) \n
- Monitoring panels and dashboards (updating currency rates, stock quotes) \n
- Collaborative document editing (Google Docs-like) \n
- Real-time notifications (new orders, alerts) \n
- Multiplayer games \n
- Progress of long-running operations (file uploads, data processing) \n
SignalR automatically selects the best transport protocol for the connection:
\n- \n
- WebSocket — the most efficient, persistent two-way connection \n
- Server-Sent Events (SSE) — one-way transmission from server to client \n
- Long Polling — fallback mechanism if WebSocket and SSE are unavailable \n
Installing SignalR
\n\nServer-side installation (ASP.NET Core)
\nFor the server side, use the NuGet package. Run in the terminal:
\ndotnet add package Microsoft.AspNetCore.SignalR\nOr via Package Manager Console in Visual Studio:
\nInstall-Package Microsoft.AspNetCore.SignalR\n\nInstalling the client for JavaScript (browser)
\nFor the client side (browser), use npm:
\nnpm install @microsoft/signalr\nOr include via CDN:
\n<script src="https://cdnjs.cloudflare.com/ajax/libs/microsoft-signalr/8.0.0/signalr.min.js"></script>\n\nInstalling the client for .NET (C#)
\nFor a C# client (e.g., console application or WPF):
\ndotnet add package Microsoft.AspNetCore.SignalR.Client\n\nQuick start: "Hello, World!" example
\n\nLet's create a simple chat: the server receives a message and broadcasts it to all connected clients.
\n\nStep 1: Create a Hub (server side)
\nCreate a file ChatHub.cs:
using Microsoft.AspNetCore.SignalR;\n\nnamespace SignalRChat.Hubs\n{\n public class ChatHub : Hub\n {\n public async Task SendMessage(string user, string message)\n {\n // Send the message to all connected clients\n await Clients.All.SendAsync("ReceiveMessage", user, message);\n }\n }\n}\n\n\nStep 2: Register SignalR in Program.cs
\nusing SignalRChat.Hubs;\n\nvar builder = WebApplication.CreateBuilder(args);\n\n// Add SignalR\nbuilder.Services.AddSignalR();\n\nvar app = builder.Build();\n\napp.MapGet("/", () => "Hello World!");\n\n// Map the hub to the /chatHub path\napp.MapHub<ChatHub>("/chatHub");\n\napp.Run();\n\n\nStep 3: Create a client (HTML + JavaScript)
\n<!DOCTYPE html>\n<html>\n<head>\n <title>SignalR Chat</title>\n</head>\n<body>\n <h2>SignalR Chat</h2>\n <div>\n <input type="text" id="userInput" placeholder="Your name" />\n <input type="text" id="messageInput" placeholder="Message" />\n <button onclick="sendMessage()">Send</button>\n </div>\n Also in library
Working with Dates in Java: Overview of Libraries and Tools
node-cron — Task Scheduler for Node.js
Elasticsearch client for C# (.NET): NEST and Elastic.Clients.Elasticsearch
Juniper: An Elegant GraphQL Library in Rust for Modern Web Applications