SignalR for ASP.NET Developers

26
ASP.NET SignalR By Shivanand Arur

description

 

Transcript of SignalR for ASP.NET Developers

Page 1: SignalR for ASP.NET Developers

ASP.NET SignalR

By Shivanand

Arur

Page 2: SignalR for ASP.NET Developers

Topics Focused On!!!

• Traditional Web Approach

• What does “Real Time” mean?

• SignalR – “The Rockstar”

• Quick Glance at - Transport Techniques

• Types of Connections

• How do I get SignalR?

• Demo

Page 3: SignalR for ASP.NET Developers

CLIENT

SERVER

Traditional Web Approach

Sends a Request to the Server – (Step 1)[In other words, the Client is trying to

pull some information from the Server]

Processes the Request

(Step 2)

Response Sent back to the Client – (Step 3)

Page 4: SignalR for ASP.NET Developers

Real Time Web Applications

Page 5: SignalR for ASP.NET Developers

What is Real Time Web Application?

• In simple terms, “Real Time” means an immediate response being sent by the Server to the Client.

• Real Time is all about “Pushing” instead of “Pulling”

• Push Technology is completely different from Pull Technology. Its about getting told what’s new, instead of asking for what’s new!!!

• Facebook, Twitter, Yahoo Cricket Live, Stock Ticker

Page 6: SignalR for ASP.NET Developers

CLIENT

SERVER

User Sends a Request to the Server

Creates a Persistent Connection between them

Real Time Web Approach

Response Sent back to the Client

Response Sent back to the Client

Response Sent back to the Client

Page 7: SignalR for ASP.NET Developers

SignalR – The Rockstar

• SignalR is an asynchronous library. Used to develop Real Time Web Application.

• Concept intiated by “David Fowler” and “Damien Edwards”

• Provides Client to Server persistent connection over HTTP.

• Makes use of Push Technology.

• Provides Abstraction over the set of transports.

• Open Source available on Github!!!

Page 8: SignalR for ASP.NET Developers

SignalR

Transport Techniques

Connections

Page 9: SignalR for ASP.NET Developers

Transport Priority

WebSockets

Server-Sent events

Forever Frame (IE hack)

Long Polling

Page 10: SignalR for ASP.NET Developers

WebSocket

• A new transport technique which came up with HTML5.

• It internally works on top of TCP protocol.

Pros Cons

Full-duplex persistent connection (both ways)

Supported only on latest browsers – (IE 10)

Fastest solution Works only with IIS-8.0

Page 11: SignalR for ASP.NET Developers

Server Sent Events

• Requires a single connection between Client-Server.

• Uses Javascript API – “EventSource” through which Client can request a particular URL to receive data stream.

• Used to send Message Notifications or Continuous Data Streams.

Pros ConsNo need to reconnect Works in server-to-client

direction onlyNot supported in IE

Page 12: SignalR for ASP.NET Developers

Forever Frames

• Data is sent out in chunks.

• Internally creates an Iframe along with a script on the page to fetch the data.

Pros ConsSupported on IE Browser. Iframes are loaded again

and again with chunks of data.All script tags remain on the page

Page 13: SignalR for ASP.NET Developers

Long Polling

Server

Client

Time: requests event ‘n’ seconds (variable)

Requ

est

Resp

onse

Variable delay

Page 14: SignalR for ASP.NET Developers

Hubs

Persistent Connection

SignalR Connections

Page 15: SignalR for ASP.NET Developers

Persistent Connection

• Provides a raw / low-level control to manage connection.

• Contain events like “OnConnection”, “OnDisconnection”, “OnReconnection”

• We can write our own logic in these events.

Page 16: SignalR for ASP.NET Developers

Hubs

• Provides a High-level API.

• Client calling Server.

• Server calling Clients. (All, Groups, One).

• Broadcasting messages to all connected clients.

• Works in a similar way like a “Controller”

Page 17: SignalR for ASP.NET Developers

How do I get SignalR?

Page 18: SignalR for ASP.NET Developers
Page 19: SignalR for ASP.NET Developers
Page 20: SignalR for ASP.NET Developers
Page 21: SignalR for ASP.NET Developers

Some References!!!

Some JQuery!!!

Page 22: SignalR for ASP.NET Developers

Routing is Very Important!!!

Page 23: SignalR for ASP.NET Developers

Server Calling Client

Page 24: SignalR for ASP.NET Developers

Client Calling Server Function

Page 25: SignalR for ASP.NET Developers

DEMO

Page 26: SignalR for ASP.NET Developers

Thanks for Listening!!!