SignalR Real-Time Communication in ASP.NET Core
π‘ Concept Name
SignalR in ASP.NET Core
π Quick Intro
SignalR is a library in ASP.NET Core that enables real-time communication between server and client over WebSockets, Server-Sent Events, or Long Pollingβallowing instant updates to the UI without refreshing.
π§ Analogy / Short Story
Think of SignalR as a walkie-talkie between your server and browser. Instead of shouting and hoping the browser hears it later (traditional polling), SignalR keeps the channel open so messages are sent and heard immediately.
π§ Technical Explanation
SignalR abstracts transport protocols and allows bi-directional communication using WebSockets where possible, and gracefully falls back to SSE or long polling. It enables real-time push-style updates such as notifications, live chat, or dashboards.
It supports scale-out via Redis backplanes and integrates well with Blazor, React, or plain JS clients.
π― Purpose & Use Case
- β Live chat applications
- β Real-time dashboards and analytics
- β Notifications (stock price, orders, social updates)
- β Collaborative apps (whiteboards, docs)
- β Multiplayer gaming and live polling
π» Real Code Example
SignalR Chat Example:
// ChatHub.cs
public class ChatHub : Hub
{
public async Task SendMessage(string user, string message)
{
await Clients.All.SendAsync("ReceiveMessage", user, message);
}
}
// Program.cs
builder.Services.AddSignalR();
app.MapHub<ChatHub>("/chathub");
// client.js
const connection = new signalR.HubConnectionBuilder()
.withUrl("/chathub").build();
connection.on("ReceiveMessage", (user, message) => {
console.log(`${user}: ${message}`);
});
connection.start().then(() => {
connection.invoke("SendMessage", "Alice", "Hello!");
});
Highlight: One hub, multiple clients, real-time communication enabled with minimal setup.

β Interview Q&A
Q1: What is SignalR?
A: A real-time communication library for ASP.NET Core that enables server-to-client push functionality.
Q2: How does SignalR select transport?
A: It auto-negotiates the best transport: WebSockets, Server-Sent Events, or Long Polling.
Q3: What is a Hub in SignalR?
A: A central class through which clients and server communicate in SignalR.
Q4: How does a client subscribe to a SignalR hub?
A: By using the `HubConnectionBuilder` and attaching listeners for specific methods.
Q5: Is SignalR supported in Blazor?
A: Yes, especially in Blazor Server apps.
Q6: How do you scale SignalR with multiple servers?
A: Using a backplane like Redis.
Q7: Does SignalR support authentication?
A: Yes, it can use cookie or bearer-based authentication.
Q8: Can SignalR push to specific users?
A: Yes, via connection IDs, user identifiers, or groups.
Q9: Is SignalR part of .NET Core SDK?
A: It is part of ASP.NET Core and needs `Microsoft.AspNetCore.SignalR` NuGet package.
Q10: Can I use SignalR without JavaScript?
A: Yes, with .NET, Java, or Python clients.
π MCQs
Q1: What transport does SignalR prefer?
- A. Long Polling
- B. WebSockets
- C. FTP
- D. SignalPipe
Q2: Which namespace is needed for SignalR hubs?
- A. Microsoft.Realtime
- B. Microsoft.AspNetCore.SignalR
- C. System.Hub
- D. SignalR.IO
Q3: What is used to start a SignalR connection?
- A. signalR.begin()
- B. connection.start()
- C. hub.connect()
- D. start.signal()
Q4: Which method is used to call a server method from client?
- A. emit()
- B. invoke()
- C. call()
- D. send()
Q5: How do you send message to all clients in a hub?
- A. Clients.Send()
- B. Clients.All.SendAsync()
- C. Broadcast()
- D. Clients.BroadcastAsync()
Q6: What is the fallback for WebSockets in SignalR?
- A. AJAX
- B. Server-Sent Events
- C. GraphQL
- D. SignalHTTP
Q7: Can you create SignalR clients in Python?
- A. No
- B. Yes
- C. Only JS
- D. Only .NET
Q8: Which is not a SignalR feature?
- A. Real-time updates
- B. SQL replication
- C. Group messaging
- D. Automatic reconnection
Q9: What class do hubs derive from?
- A. WebHub
- B. Hub
- C. BaseHub
- D. SignalController
Q10: How does SignalR scale out in multiple servers?
- A. WebFarm
- B. Redis backplane
- C. Round robin
- D. LoadHub
π‘ Bonus Insight
SignalR integrates directly with Azure SignalR Service, letting you scale to millions of concurrent connections with simplified connection management and traffic handling.
π PDF Download
Need a handy summary for your notes? Download this topic as a PDF!