1. Introduction to the Real-Time Web and ASP.NET SignalR
The Internet is one of the most important inventions in history, and it has changed our lives for the better in many ways. For social creatures such as humans, nothing could be better than a fast method of communication with the world that enables multimedia content delivery with almost no delay.
In its few decades of existence, the Internet has evolved from a basic set of network clusters with simple operations to the foundation of almost everything in our world, providing opportunities to make billions of dollars.
Our mission in this book is to walk you (and other Microsoft web developers with a good background in ASP.NET and JavaScript) through a very recent technology called ASP.NET SignalR. It enables the creation of real-time, asynchronous web applications that are the most modern type of infrastructure for building sites to deliver content from servers to clients in real time and remove any latency. Clients sit on a page on your site and receive the newest updates in real time with no need to click anything or refresh the page. For example, on Facebook when somebody leaves a comment or likes one of your photos, you do not need to refresh the page to see the notification pop up and the red counter being updated. ASP.NET SignalR provides the foundation to develop such features.
This chapter gives you some background information on SignalR and how it can help you build modern web sites. The following are the major topics covered in this chapter:
How the Internet has evolved to where it is today
Why client-side experience is more important than ever
Definition of realtime web application development
Some examples of realtime web application development
Historical overview of ASP.NET SignalR
Introduction to ASP.NET SignalR and some of its characteristics
ASP.NET SignalR architecture
Overview of different transport options in ASP.NET SignalR
Main challenges for realtime web development
Evolution of the Internet
The Internet started as a simple set of clusters with some computers connected to perform basic operations. It quickly became a very sophisticated network of servers all around the world that serve hundreds of millions (even billions) of clients.
There have been different kinds of changes on this worldwide network in different domains. In one area, Internet connections became faster and more reliable, enabling users to download and upload larger content so that it is now possible for users to download and upload highquality multimedia content (e.g., videos) from their mobile Internet connections. It has also opened new doors for content providers and consumers.
In another area, Internet browsers evolved to be very sophisticated, and enabled features to facilitate the creation and delivery of content in more user-friendly ways. For at least a decade, the use of Asynchronous JavaScript and XML (AJAX) technologies has given a smoother user experience to end users, for example.
In a third area, server technologies have evolved to also accommodate browser and connection advancements. New programming languages and platforms have been introduced, along with many libraries that help simplify the process of web application creation for web developers. One of these recent advancements is the support for WebSockets.
All the different trends on the Internet focused on providing a better user experience. We have moved from serving static HTML web pages to dynamic pages that can be updated based on users actions. We can then use client-side languages (mostly JavaScript) to process certain things on the browser and reduce the need to refresh a web page to get the new content. Currently, there is a more modern approach: real-time delivery of content from servers to clients that is possible by applying server-side technologies in conjunction with JavaScript. This is the area in which SignalR comes into play.
Why the Client-Side Experience Is More Important than Ever
The concept of user has become the most important concept in todays Internet. Almost all businesses, regardless of their size, know how important the user experience can be. They have moved their focus to making products, technologies, and software that is intuitive and simple enough to attract almost any user regardless of age, gender, cultural background, and so on.
An important part of the user experience is the speed of delivering content. Traditionally, the Internet was a set of web pages served on servers and received by clients. These pages included many static pages that could not react dynamically to users actions and dynamic pages that could render a dynamic content based on the inputs provided by users. Users had to send their actions to servers or request a particular Uniform Resource Locator (URL) from the server to receive HTML content. This was a very simple model and lacked the sophistication seen in modern web sites.
As the user experience became more important, web designers and developers came up with the idea of using JavaScript and XML in conjunction with partial content rendering on the servers to take advantage of the concept of AJAX. It would provide a smoother experience to users and deliver content to these users more quickly.
In the past few years, however, this approach wasnt good enough for the modern needs of the Internet. Even with AJAX, there was often a wait for users actions to update a portion of the page and deliver the content, so the speed of content delivery was very dependent on the speed of the users interactions.
This issue led web developers and designers to start thinking about sending the content from servers to clients as it arrives in real time, or at least invent mechanisms that simulate such a behavior. This process is called realtime web application development .
RealTime Web Application Development
The term real-time software refers to the type of software that is subject to a soft or hard time constraint. By the nature of its business domain, this type of software must complete its processing within a particular timeframe. This time constraint can be strict to make it hard real-time software or flexible to make it soft real-time software. For example, aerospace software can be hard real-time software because it must finish its execution within a defined time interval; otherwise, operations might fail, and peoples lives can be in danger. In contrast, video players can be soft real-time software because it is not mission-critical if the processing does not finish on time (although it is important to process the videos in time to display them to users).
Although real-time software and real-time computing have been around for a long time, the term real-time web is relatively new. This concept, which was introduced in the past few years, focuses on real-time delivery of content to clients as soon as it is available.
The real-time web is similar to soft real-time software because the delivery of content from the information source to consumers should occur in a short period of time to be considered real time (from a few milliseconds up to 1 second).
The real-time web was embraced by social networks and their need to update users with frequent status updates and content changes by friends and peers. Facebook and Twitter were among the first major sites on the Internet that pioneered in this area and implemented real-time web features.