Welcome to this review of SignalR, the final module of the Pluralsight course One ASP.NET From Scratch by Jesse Liberty and Jeff Fritz.
Jeff Fritz is a Program Manager for Microsoft in the ASP.NET and Azure Developer Experience teams.
Currently, he leads the NuGet team and manages the MSDN Web Developer Tools blog.
Prior to joining Microsoft, he was a Microsoft MVP, ASPInsider, INETA Community Champion and Developer Advocate for Telerik.
Also in this series:
Part 1 – One ASP.NET From Scratch
Part 2 – Advanced Web Forms
Part 3 – MVC
Part 4 – Advanced MVC
Part 5 – MVC and AJAX
Part 6 – Web Pages
Part 7 – Web API
Part 8 – SignalR
SignalR
SignalR is a ‘real-time’ HTTP-based communication framework, which is capable of running in all browsers with JavaScript.
It uses Web Sockets where available to falls back to older technologies, ending with plain old Polling for the worst browsers.
It provides server and client execution APIs, and is capable of being sel-hosted.
Jeff explains what Real-Time Web means with the aid of some illustrations. We get much more dynamic interaction between the client and the server.
We also learn about the three SignalR models:
- Broadcast
- Interactive
- Games
The Server-side implementation is known as the SignalR Hub.
We also typically use a JavaScript Client, which dynamically adds to the jQuery framework.
SignalR Demo – The ChatHub
Jeff demonstrates an application that allows many people to chat in real time.
This involves creating a class ChatHub which inherits from Hub and writing a SendMessage method.
In RouteConfig.cs we write in the RegisterRoutes method Routes.MapHubs();
We also see jQuery code written in a script block in the markup file.
Jeff shows us that chat messages instantly appear in both browsers.
Next we enhance the app with a connection count, and track when new users join the ChatHub. This involves overriding the OnConnected Task.
When a new user joins, we increment the connection count and report the news to all connected clients.
It’s a very similar process when users disconnect as well: we just override the OnDisconnected Task.
Jeff displays the connection count in the view and demonstrates this number increasing as more clients connect to the ChatHub service.
Jeff also explains that there are other client’s available in we don’t want to use SignalR in the browser. There are clients available for .NET, iOS, Android etc.
You can learn more at signalr.net
Jeff also recommends checking out the massively multiplayer game shootr.signalr.net
Further Resources
Other Pluralsight courses available for learning SignalR include:
SignalR Across Web and Devices
Introducing ASP.NET SignalR – Push Services with Hubs
Building a Game of Memory with SignalR by Joel Neubeck
Stateful Reactice Concurrent SPAs with SignalR and Akka.net by Jason Roberts
Building Apps with Azure Mobile Svcs, SignalR, MVC, Win 8 and WP8 by Colin Melia