Real-Time Web
Lesson 1
Client-Server Communication in ASP.NET MVC
#SignalR
By Muhammad Bilal Amjad
Afterthissessionyouwill becapableofusing:
Real Time Functionalities
Client-Server Communication
SignalR
Various Use Cases
How does SignalR Works
Session being delivered by: Muhammad Bilal Amjad
www.bilalamjad.net | bilalamjad@azurewebsites.net
What is SignalR
Adding real-tine web functionality to applications.
Handles connection management automatically and lets you broadcast messages to
all connected clients simultaneously, like a chat room.
You can also send messages to specific clients.
Create persistent connection between server and client(s) in ASP.NET allowing you to
push data from server to client unlike a classic HTTP connection whish is re-
established for each communication.
Available at Nuget Packages, use “install-package signalr” command to add it into
your project.
Examples and Use-cases
Chat
Real-time impact analysis on current users.
Implementing Push notifications and pub-sub mechanisms.
Real-time charting without repeat client-side ajax polling
Collaborative applications allowing multiple users to interact with the same screen.
Real-time analytics dashboard showing client details (Geo-location based on IP
address browser info, screen resolution, etc)
Transport Mechanisms
SignalR uses one of multiple technologies to set up communications between client
and server. Web Socket, which was introduced with HTML5, provides bidirectional
support but it is not supported by all the browsers and older versions.
As we can’t guarantee what browser will be used by the user, we can’t simply rely on
this, so there must be some way which can implement similar features across
browsers. To do t his, SignalR allows you to use multiple transport technologies and
select one which is most suitable for the scenario.
Web Sockets
Web Socket – This communication technology provides a true two-way
communication over a single TCP connection on web.
In other words, if both the parties (Client and server) supports web socket, then this
creates a persistent connection between them which can be used by either client or
server to send the data anytime. As such, this is most efficient, takes less memory and
shows the lowest latency. This is the most preferred protocol for a SignalR application.
Server Sent Events (Event Source)
Server Sent Events (also known as Event Source) – This is another technique
introduced with HTML5 which allows the server to push the updates to the client
whenever new data is available. This technology is used when Web Socket is not
supported. It is supported by most browsers except IE.
Forever Frame
This is part of the COMET model.
Comet is a web application model in which a long-held HTTPS request allows
a web server to push data to a browser, without the browser explicitly requesting it.
Forever frame uses a hidden iframe on the browser to receive the data in an
incremental manner from the server. The server starts sending the data in a series of
chunks even without even knowing the complete length of the content. It is executed
on the client when the data is received.
Ajax Long Polling
This is the least preferred way in SignalR to set up a communication between Client
and Server. Also, it is the most expensive amongst all, too! It is a part of the COMET
model and as the name suggests, it keeps polling the server to check for updates. The
request that is sent to the server is AJAX based, to minimize the resource usage and
provide a better user experience. But it’s still expensive because it keeps polling the
server whether there are any updates or not.
How SignalR Works
Session being delivered by: Muhammad Bilal Amjad
www.bilalamjad.net | bilalamjad@azurewebsites.net
SignalR Persistent Connection
This is a lower level API which allows us to send raw messages to different clients. We
can also customize this based on the different types of messages and different clients,
and can send these details with the message as well. In simple words, on one hand it
gives us more control over connecting and sending different types of messages, while
on the other hand we need to write more code.
SignalR Hubs
Hubs – These are higher level APIs which are built on top of the Persistent
connections. Hubs hide all the complexities from the developer and provide us a
simple RPC style model with the unique function defined.
Remote Procedure Call (RPC) is a protocol that one program can use to request a
service from a program located in another computer on a network without having to
understand the network's details.
Next Lesson : Configuring SignalR
Thank you for watching
Thank you!
You can follow me
@mbilalamjad/
www.bilalamjad.net
www.facebook.com/bilal.amjad

Real Time Web with SignalR

  • 1.
    Real-Time Web Lesson 1 Client-ServerCommunication in ASP.NET MVC #SignalR By Muhammad Bilal Amjad
  • 2.
    Afterthissessionyouwill becapableofusing: Real TimeFunctionalities Client-Server Communication SignalR Various Use Cases How does SignalR Works Session being delivered by: Muhammad Bilal Amjad www.bilalamjad.net | bilalamjad@azurewebsites.net
  • 3.
    What is SignalR Addingreal-tine web functionality to applications. Handles connection management automatically and lets you broadcast messages to all connected clients simultaneously, like a chat room. You can also send messages to specific clients. Create persistent connection between server and client(s) in ASP.NET allowing you to push data from server to client unlike a classic HTTP connection whish is re- established for each communication. Available at Nuget Packages, use “install-package signalr” command to add it into your project.
  • 4.
    Examples and Use-cases Chat Real-timeimpact analysis on current users. Implementing Push notifications and pub-sub mechanisms. Real-time charting without repeat client-side ajax polling Collaborative applications allowing multiple users to interact with the same screen. Real-time analytics dashboard showing client details (Geo-location based on IP address browser info, screen resolution, etc)
  • 5.
    Transport Mechanisms SignalR usesone of multiple technologies to set up communications between client and server. Web Socket, which was introduced with HTML5, provides bidirectional support but it is not supported by all the browsers and older versions. As we can’t guarantee what browser will be used by the user, we can’t simply rely on this, so there must be some way which can implement similar features across browsers. To do t his, SignalR allows you to use multiple transport technologies and select one which is most suitable for the scenario.
  • 6.
    Web Sockets Web Socket– This communication technology provides a true two-way communication over a single TCP connection on web. In other words, if both the parties (Client and server) supports web socket, then this creates a persistent connection between them which can be used by either client or server to send the data anytime. As such, this is most efficient, takes less memory and shows the lowest latency. This is the most preferred protocol for a SignalR application.
  • 7.
    Server Sent Events(Event Source) Server Sent Events (also known as Event Source) – This is another technique introduced with HTML5 which allows the server to push the updates to the client whenever new data is available. This technology is used when Web Socket is not supported. It is supported by most browsers except IE.
  • 8.
    Forever Frame This ispart of the COMET model. Comet is a web application model in which a long-held HTTPS request allows a web server to push data to a browser, without the browser explicitly requesting it. Forever frame uses a hidden iframe on the browser to receive the data in an incremental manner from the server. The server starts sending the data in a series of chunks even without even knowing the complete length of the content. It is executed on the client when the data is received.
  • 9.
    Ajax Long Polling Thisis the least preferred way in SignalR to set up a communication between Client and Server. Also, it is the most expensive amongst all, too! It is a part of the COMET model and as the name suggests, it keeps polling the server to check for updates. The request that is sent to the server is AJAX based, to minimize the resource usage and provide a better user experience. But it’s still expensive because it keeps polling the server whether there are any updates or not.
  • 10.
    How SignalR Works Sessionbeing delivered by: Muhammad Bilal Amjad www.bilalamjad.net | bilalamjad@azurewebsites.net
  • 11.
    SignalR Persistent Connection Thisis a lower level API which allows us to send raw messages to different clients. We can also customize this based on the different types of messages and different clients, and can send these details with the message as well. In simple words, on one hand it gives us more control over connecting and sending different types of messages, while on the other hand we need to write more code.
  • 12.
    SignalR Hubs Hubs –These are higher level APIs which are built on top of the Persistent connections. Hubs hide all the complexities from the developer and provide us a simple RPC style model with the unique function defined. Remote Procedure Call (RPC) is a protocol that one program can use to request a service from a program located in another computer on a network without having to understand the network's details.
  • 13.
    Next Lesson :Configuring SignalR Thank you for watching
  • 14.
    Thank you! You canfollow me @mbilalamjad/ www.bilalamjad.net www.facebook.com/bilal.amjad