SlideShare a Scribd company logo
1 of 27
KNOWLEDGE FOR LIFEKNOWLEDGE FOR LIFE
Tech Demo
Building Real-time
Applications with
SignalR
28th Feb 2017
KNOWLEDGE FOR LIFE
What we’ll be covering today
●What is SignalR?
●Why Use SignalR
●How Does SignalR Work
●The SignalR Hub Class & jQuery Plugin
●SignalR .NET Client
●Hubs and Persistent Connections
●SignalR Implementation
KNOWLEDGE FOR LIFE
SignalR is an abstraction that
intelligently decides how to
enable real-time over HTTP
KNOWLEDGE FOR LIFE
What is SignalR ?
●SignalR allows to create Real Time apps over Http.
●Http- A stateless protocol.
●Real Time-If something happens on the servers, the clients will be
notified without any post back.
●Good for chat applications, games, new and stock market updates.
KNOWLEDGE FOR LIFE
How Does SignalR Work?
●Example of Social Network.
●It Uses 4 Different Technologies-
1. Web Sockets
2. Event Source
3.Forever Frame
4.Long Polling
●SignalR Chooses among the technologies depending on the
requirements.
KNOWLEDGE FOR LIFE
Normal Http Web Request
Here’s some data!
No
Here’s some data!
KNOWLEDGE FOR LIFE
Ajax Request
●Client side validation not enough in web applications.
●Ajax can help in Server side validation without loading the whole page.
KNOWLEDGE FOR LIFE
Ajax Request Explained
Here’s some data!
No
Here’s the data you wanted!
KNOWLEDGE FOR LIFE
Limitation of Ajax Request
● Client needs to request to the server.
● Once the response comes, all the connection is lost.
KNOWLEDGE FOR LIFE
Long Polling Explained
Here’s some data!
Here’s some data!
KNOWLEDGE FOR LIFE
Limitation of Long Polling
● It is not a persistent connection.
● Internally it makes request to the server to remind who is it.
● It is one way only.
● Looks like a Persistent connection, but is not
KNOWLEDGE FOR LIFE
Forever Frame
●Best Example- Iframe
●E.g. YouTube Video on HTML
●Server can call Client side function, and push data as well.
PUSH DATA
KNOWLEDGE FOR LIFE
Limitation of Forever Frame
● Takes up RAM just by sitting there in the iframe.
● Client must support iframe, e.g. Web Browsers.
● It is one way only (Server to Client Only).
KNOWLEDGE FOR LIFE
Web Sockets
●Bi-Directional => Persistent Connection
●Multiple Users
●Full Duplex (Server to Client and Client to Server communication at the
same time)
●Asynchronous
KNOWLEDGE FOR LIFE
Yeah, dude!
KNOWLEDGE FOR LIFE
Real Time Field Status To Researchers
0%
10%
20%
30%
40%
50%
60%
70%
80%
90%
100%
2013 2014 2015 2016
Pulses
Wheat
Rice
KNOWLEDGE FOR LIFE
Why use SignalR ?
●When we use SignalR, all the 4 technologies are implemented.
●In case of updates SignalR takes care of it.
●Abstraction-No need to understand the complexity.
●Cross compatible-Many browsers, Not only web but other apps.
●Easy
●Scalability- Multi Server situation. Just Need hardware to back it up.
KNOWLEDGE FOR LIFE
SignalR is built almost entirely
using async, so you don’t need
to worry about blocking
threads
KNOWLEDGE FOR LIFE
Try It Yourself
● PM> Install-Package Microsoft.AspNet.SignalR.Sample
KNOWLEDGE FOR LIFE
Server Side – Hub 1/2
● Top layer of Persistent Connection
● Can connect with 1-N clients
● Can send messages and call methods
● Routes automatically mapped
● SignalR handle the binding of complex object and arrays of objects
automatically
● Communication is serialized by JSON
● Hubs are per call, which means, each call from client to the hub will create a
new hub instance. Don’t setup static event handlers in hub methods.(3)
KNOWLEDGE FOR LIFE
Server Side – Hub 2/2
public class ChatHub : Hub
{
public void Send(string name, string message)
{
//Call the broadcast message method to update all clients
Clients.All.broadcastMessage(name , message);
}
}
KNOWLEDGE FOR LIFE
Client Side 1/3
<script src="Scripts/jquery-1.8.2.min.js" ></script>
<script src="Scripts/jquery.signalR-1.0.0.min.js" ></script>
<script src="/signalr/hubs" ></script>
<script type="text/javascript">
$(function () {
//Declare a proxy to reference the hub
var chat = $.connection.chatHub;
//Create a function that the hub can call to broadcast messages
= function (name, message) {
//Omitted
};
//Start the connection
(function () {
$("#sendMessage").click(function () {
//Call the Send method on the hub
chat.server.send($("#displayName").val(), $("#message").val());
});
});
});
</script>
KNOWLEDGE FOR LIFE
● Exposing methods from the server - The JavaScript client can declare methods
that the server can invoke.
my.Hub.{method} = callback
Method – Name of the client side method
Callback – A function to execute when the server invokes the method
● If you misspell names you will not get any warnings or notifications even
when logging is enabled. On server side is method call hosted on dynamic
property (Clients)
Client Side 2/3
KNOWLEDGE FOR LIFE
● JavaScript API
● $.connection.hub – The connection for all hubs
● $.connection.hub.id – The client id for the hub connection
● $.connection.hub.logging – Set to true to enable logging.
● $.connection.hub.start() – Starts the connection for all hubs.
Client Side 3/3
KNOWLEDGE FOR LIFE
● Register the route for generated SignalR hubs
1. Register on server side in StartUp class:
public partial class StartUp
{
protected void Configuration(IAppBuilder app)
{
app.MapSignalR();
}
}
2. Register on client side:
<script src="/signalr/hubs" ></script>
Hub Routing
KNOWLEDGE FOR LIFE
Simple Chat Application
KNOWLEDGE FOR LIFE
Thank You

More Related Content

Similar to SignalR Technical Demo

SignalR powered real-time x-plat mobile apps!
SignalR powered real-time x-plat mobile apps!SignalR powered real-time x-plat mobile apps!
SignalR powered real-time x-plat mobile apps!Sam Basu
 
SignalR Powered X-Platform Real-Time Apps!
SignalR Powered X-Platform Real-Time Apps!SignalR Powered X-Platform Real-Time Apps!
SignalR Powered X-Platform Real-Time Apps!Sam Basu
 
Real-Time Web applications with WebSockets
Real-Time Web applications with WebSocketsReal-Time Web applications with WebSockets
Real-Time Web applications with WebSocketsStanislav Zozulia
 
Programmable infrastructure with FlyScript
Programmable infrastructure with FlyScriptProgrammable infrastructure with FlyScript
Programmable infrastructure with FlyScriptRiverbed Technology
 
Gwt session
Gwt sessionGwt session
Gwt sessionMans Jug
 
Asynchrone Echtzeitanwendungen für SharePoint mit SignalR und knockout.js
Asynchrone Echtzeitanwendungen für SharePoint mit SignalR und knockout.jsAsynchrone Echtzeitanwendungen für SharePoint mit SignalR und knockout.js
Asynchrone Echtzeitanwendungen für SharePoint mit SignalR und knockout.jsChristian Heindel
 
What's New with Windows Phone - FoxCon Talk
What's New with Windows Phone - FoxCon TalkWhat's New with Windows Phone - FoxCon Talk
What's New with Windows Phone - FoxCon TalkSam Basu
 
Website Monitoring with Distributed Messages/Tasks Processing (AMQP & RabbitM...
Website Monitoring with Distributed Messages/Tasks Processing (AMQP & RabbitM...Website Monitoring with Distributed Messages/Tasks Processing (AMQP & RabbitM...
Website Monitoring with Distributed Messages/Tasks Processing (AMQP & RabbitM...Jimmy DeadcOde
 
Using Groovy to empower WebRTC Network Systems
Using Groovy to empower WebRTC Network SystemsUsing Groovy to empower WebRTC Network Systems
Using Groovy to empower WebRTC Network Systemsantonry
 
Google App Engine Overview - BarCamp Phnom Penh 2011
Google App Engine Overview - BarCamp Phnom Penh 2011Google App Engine Overview - BarCamp Phnom Penh 2011
Google App Engine Overview - BarCamp Phnom Penh 2011traactivity
 
Bringing Learnings from Googley Microservices with gRPC - Varun Talwar, Google
Bringing Learnings from Googley Microservices with gRPC - Varun Talwar, GoogleBringing Learnings from Googley Microservices with gRPC - Varun Talwar, Google
Bringing Learnings from Googley Microservices with gRPC - Varun Talwar, GoogleAmbassador Labs
 
Telestax TADHack Presentation
Telestax TADHack PresentationTelestax TADHack Presentation
Telestax TADHack PresentationAlan Quayle
 
ONLINE FOOD ORDERS THROUGH WHATSAPP AUTOMATION BOT
ONLINE FOOD ORDERS THROUGH WHATSAPP AUTOMATION BOTONLINE FOOD ORDERS THROUGH WHATSAPP AUTOMATION BOT
ONLINE FOOD ORDERS THROUGH WHATSAPP AUTOMATION BOTIRJET Journal
 
Secure Developer Access at Decisiv
Secure Developer Access at DecisivSecure Developer Access at Decisiv
Secure Developer Access at DecisivTeleport
 

Similar to SignalR Technical Demo (20)

SignalR powered real-time x-plat mobile apps!
SignalR powered real-time x-plat mobile apps!SignalR powered real-time x-plat mobile apps!
SignalR powered real-time x-plat mobile apps!
 
SignalR Powered X-Platform Real-Time Apps!
SignalR Powered X-Platform Real-Time Apps!SignalR Powered X-Platform Real-Time Apps!
SignalR Powered X-Platform Real-Time Apps!
 
LoadTracer
LoadTracer LoadTracer
LoadTracer
 
Real-Time Web applications with WebSockets
Real-Time Web applications with WebSocketsReal-Time Web applications with WebSockets
Real-Time Web applications with WebSockets
 
Programmable infrastructure with FlyScript
Programmable infrastructure with FlyScriptProgrammable infrastructure with FlyScript
Programmable infrastructure with FlyScript
 
Webrtc in Real world
Webrtc in Real world Webrtc in Real world
Webrtc in Real world
 
Gwt session
Gwt sessionGwt session
Gwt session
 
Asynchrone Echtzeitanwendungen für SharePoint mit SignalR und knockout.js
Asynchrone Echtzeitanwendungen für SharePoint mit SignalR und knockout.jsAsynchrone Echtzeitanwendungen für SharePoint mit SignalR und knockout.js
Asynchrone Echtzeitanwendungen für SharePoint mit SignalR und knockout.js
 
Gwt session
Gwt sessionGwt session
Gwt session
 
Gripshort
GripshortGripshort
Gripshort
 
What's New with Windows Phone - FoxCon Talk
What's New with Windows Phone - FoxCon TalkWhat's New with Windows Phone - FoxCon Talk
What's New with Windows Phone - FoxCon Talk
 
Website Monitoring with Distributed Messages/Tasks Processing (AMQP & RabbitM...
Website Monitoring with Distributed Messages/Tasks Processing (AMQP & RabbitM...Website Monitoring with Distributed Messages/Tasks Processing (AMQP & RabbitM...
Website Monitoring with Distributed Messages/Tasks Processing (AMQP & RabbitM...
 
Using Groovy to empower WebRTC Network Systems
Using Groovy to empower WebRTC Network SystemsUsing Groovy to empower WebRTC Network Systems
Using Groovy to empower WebRTC Network Systems
 
Google App Engine Overview - BarCamp Phnom Penh 2011
Google App Engine Overview - BarCamp Phnom Penh 2011Google App Engine Overview - BarCamp Phnom Penh 2011
Google App Engine Overview - BarCamp Phnom Penh 2011
 
Signal R 2015
Signal R 2015Signal R 2015
Signal R 2015
 
Bringing Learnings from Googley Microservices with gRPC - Varun Talwar, Google
Bringing Learnings from Googley Microservices with gRPC - Varun Talwar, GoogleBringing Learnings from Googley Microservices with gRPC - Varun Talwar, Google
Bringing Learnings from Googley Microservices with gRPC - Varun Talwar, Google
 
Telestax TADHack Presentation
Telestax TADHack PresentationTelestax TADHack Presentation
Telestax TADHack Presentation
 
GDG Ibadan #pwa
GDG Ibadan #pwaGDG Ibadan #pwa
GDG Ibadan #pwa
 
ONLINE FOOD ORDERS THROUGH WHATSAPP AUTOMATION BOT
ONLINE FOOD ORDERS THROUGH WHATSAPP AUTOMATION BOTONLINE FOOD ORDERS THROUGH WHATSAPP AUTOMATION BOT
ONLINE FOOD ORDERS THROUGH WHATSAPP AUTOMATION BOT
 
Secure Developer Access at Decisiv
Secure Developer Access at DecisivSecure Developer Access at Decisiv
Secure Developer Access at Decisiv
 

Recently uploaded

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 

Recently uploaded (20)

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 

SignalR Technical Demo

  • 1. KNOWLEDGE FOR LIFEKNOWLEDGE FOR LIFE Tech Demo Building Real-time Applications with SignalR 28th Feb 2017
  • 2. KNOWLEDGE FOR LIFE What we’ll be covering today ●What is SignalR? ●Why Use SignalR ●How Does SignalR Work ●The SignalR Hub Class & jQuery Plugin ●SignalR .NET Client ●Hubs and Persistent Connections ●SignalR Implementation
  • 3. KNOWLEDGE FOR LIFE SignalR is an abstraction that intelligently decides how to enable real-time over HTTP
  • 4. KNOWLEDGE FOR LIFE What is SignalR ? ●SignalR allows to create Real Time apps over Http. ●Http- A stateless protocol. ●Real Time-If something happens on the servers, the clients will be notified without any post back. ●Good for chat applications, games, new and stock market updates.
  • 5. KNOWLEDGE FOR LIFE How Does SignalR Work? ●Example of Social Network. ●It Uses 4 Different Technologies- 1. Web Sockets 2. Event Source 3.Forever Frame 4.Long Polling ●SignalR Chooses among the technologies depending on the requirements.
  • 6. KNOWLEDGE FOR LIFE Normal Http Web Request Here’s some data! No Here’s some data!
  • 7. KNOWLEDGE FOR LIFE Ajax Request ●Client side validation not enough in web applications. ●Ajax can help in Server side validation without loading the whole page.
  • 8. KNOWLEDGE FOR LIFE Ajax Request Explained Here’s some data! No Here’s the data you wanted!
  • 9. KNOWLEDGE FOR LIFE Limitation of Ajax Request ● Client needs to request to the server. ● Once the response comes, all the connection is lost.
  • 10. KNOWLEDGE FOR LIFE Long Polling Explained Here’s some data! Here’s some data!
  • 11. KNOWLEDGE FOR LIFE Limitation of Long Polling ● It is not a persistent connection. ● Internally it makes request to the server to remind who is it. ● It is one way only. ● Looks like a Persistent connection, but is not
  • 12. KNOWLEDGE FOR LIFE Forever Frame ●Best Example- Iframe ●E.g. YouTube Video on HTML ●Server can call Client side function, and push data as well. PUSH DATA
  • 13. KNOWLEDGE FOR LIFE Limitation of Forever Frame ● Takes up RAM just by sitting there in the iframe. ● Client must support iframe, e.g. Web Browsers. ● It is one way only (Server to Client Only).
  • 14. KNOWLEDGE FOR LIFE Web Sockets ●Bi-Directional => Persistent Connection ●Multiple Users ●Full Duplex (Server to Client and Client to Server communication at the same time) ●Asynchronous
  • 16. KNOWLEDGE FOR LIFE Real Time Field Status To Researchers 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% 2013 2014 2015 2016 Pulses Wheat Rice
  • 17. KNOWLEDGE FOR LIFE Why use SignalR ? ●When we use SignalR, all the 4 technologies are implemented. ●In case of updates SignalR takes care of it. ●Abstraction-No need to understand the complexity. ●Cross compatible-Many browsers, Not only web but other apps. ●Easy ●Scalability- Multi Server situation. Just Need hardware to back it up.
  • 18. KNOWLEDGE FOR LIFE SignalR is built almost entirely using async, so you don’t need to worry about blocking threads
  • 19. KNOWLEDGE FOR LIFE Try It Yourself ● PM> Install-Package Microsoft.AspNet.SignalR.Sample
  • 20. KNOWLEDGE FOR LIFE Server Side – Hub 1/2 ● Top layer of Persistent Connection ● Can connect with 1-N clients ● Can send messages and call methods ● Routes automatically mapped ● SignalR handle the binding of complex object and arrays of objects automatically ● Communication is serialized by JSON ● Hubs are per call, which means, each call from client to the hub will create a new hub instance. Don’t setup static event handlers in hub methods.(3)
  • 21. KNOWLEDGE FOR LIFE Server Side – Hub 2/2 public class ChatHub : Hub { public void Send(string name, string message) { //Call the broadcast message method to update all clients Clients.All.broadcastMessage(name , message); } }
  • 22. KNOWLEDGE FOR LIFE Client Side 1/3 <script src="Scripts/jquery-1.8.2.min.js" ></script> <script src="Scripts/jquery.signalR-1.0.0.min.js" ></script> <script src="/signalr/hubs" ></script> <script type="text/javascript"> $(function () { //Declare a proxy to reference the hub var chat = $.connection.chatHub; //Create a function that the hub can call to broadcast messages = function (name, message) { //Omitted }; //Start the connection (function () { $("#sendMessage").click(function () { //Call the Send method on the hub chat.server.send($("#displayName").val(), $("#message").val()); }); }); }); </script>
  • 23. KNOWLEDGE FOR LIFE ● Exposing methods from the server - The JavaScript client can declare methods that the server can invoke. my.Hub.{method} = callback Method – Name of the client side method Callback – A function to execute when the server invokes the method ● If you misspell names you will not get any warnings or notifications even when logging is enabled. On server side is method call hosted on dynamic property (Clients) Client Side 2/3
  • 24. KNOWLEDGE FOR LIFE ● JavaScript API ● $.connection.hub – The connection for all hubs ● $.connection.hub.id – The client id for the hub connection ● $.connection.hub.logging – Set to true to enable logging. ● $.connection.hub.start() – Starts the connection for all hubs. Client Side 3/3
  • 25. KNOWLEDGE FOR LIFE ● Register the route for generated SignalR hubs 1. Register on server side in StartUp class: public partial class StartUp { protected void Configuration(IAppBuilder app) { app.MapSignalR(); } } 2. Register on client side: <script src="/signalr/hubs" ></script> Hub Routing
  • 26. KNOWLEDGE FOR LIFE Simple Chat Application