SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Kürzlich hochgeladen (20)

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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

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