In this video, explore the core concepts of SignalR and the problem it was built to solve. Also, review what SignalR does and doesn't do, and what use cases it fits well.
- [Instructor] SignalR is a library that makes it easy to add real-time functionality to applications. Let's explore exactly what real-time functionality means. A classic example is a chat application. Imagine you're building a chat app that has a server and many clients. Each client can send a message to the chat room and wants to be notified if anyone else sends a message too. One way to build this is to have each client check for new messages on the server regularly with a loop or a timer. The downside of polling with a loop is that updates are not immediate or real-time.
You either have to make the client check in very often, which means a lot of extra connections for the server to handle, or less frequently, which is easier on the server but means that updates will feel slower to users. With SignalR, the connection between the server and each client is more powerful. Instead of the client polling, or making repeated requests to the server to check for new messages, each client establishes a long-lived connection that acts as a pipe for messages in either direction. A client can send a message to the server just like before, but the server can now push messages through that pipe as well.
These connections are persistent and bi-directional, which means that you can send messages in either direction. Each client can send messages to the server, and the server can push messages to a single client or broadcast to all connected clients simultaneously. SignalR establishes and manages those pipes, or bi-directional connections between the client and the server for you. It uses a number of technologies under the hood to make those connections work, but all that is hidden from you. SignalR abstracts away the complexity of things like web sockets so you can focus on building the parts of your application that you actually care about.
This means that you don't have to worry about building the transport layer, you just get methods that make it easy to send a message from the client to the server, or from the server to one or more clients. So, what can you do with Signal R? Chat and communication apps are a common example, but there are a lot of other things you can do once you have a connection that can transport messages in either direction. You could use SignalR to push notifications, alerts, and content updates down to web clients in real-time, to build rich UI experiences. Think of an auction site that immediately shows new bids or maybe a notification icon that appears instantly when you have a new message.
You can also use SignalR for collaboration apps, such as a shared whiteboard or a document editor, or for games that require real-time communication. In this course, we'll build a simple chat example, but the principles will apply to anything else you want to build with SignalR. It's also important to cover what SignalR does not do. Since SignalR is focused on creating connections and transporting messages, it doesn't include any persistence or data storage. In other words, once you send a message, it's forgotten. If you want to show a message history or keep a log, you'll need to do that separately.
SignalR also doesn't try to manage the users connected to your application. It's focused on the connections themselves, so allowing a new user to register or check in the last time someone logged in is also outside its scope. I'll cover this in a little bit more detail as we look at how to build a project with SignalR.
- Comparing SignalR to WebSockets
- How SignalR works
- Adding a SignalR hub
- Handling hub and client connection events
- Adding connections to groups
- Adding persistence
- Adding user authentication