signalr with asp.net part1
TRANSCRIPT
SignalR
B y E s r a a A m m a r
Topics Focused On!!!• Traditional Web Approach
– Traditional Web Approach – Issues
• What does “Real Time” mean?
• SignalR– Types of Transports– Types of Connections
• How do I get SignalR?
• Demo
Traditional Web Approach“Pulling”
CLIENT
SERVER
Traditional Web ApproachSends 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)
• Not Persistent connection – IssuesEach time re-established for each communication.
• Http Request – Issues
Real Time Web Applications
What is Real Time Web Application?
• “Real Time” means an immediate response being sent by the Server to the Client.
• Real Time is “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!!!
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
Comet Transports
Long Polling
Server
Client
Requ
est
Resp
onse
Variable delay
• Long polling does not create a persistent connection, but instead polls the server with a request that stays open until the server responds, at which point the connection closes, and a new connection is requested immediately.
Forever Frames• Internally creates an Iframe along with a
script on the page to fetch the data.
• The server then continually sends script to the client which is immediately executed, providing a one-way realtime connection from server to client.
• Supported on IE Browser.
HTML5 Transports
Server Sent Events
Server Sent Events• Requires a single connection between Client-Server.
• Works in server-to-client direction only
• Used to send Message Notifications or Continuous Data Streams.
• Support a lot of Browsers but Not supported in IE.
WebSocket
WebSocket• A new HTML5 API that enables bi-directional, full duplex
communication between the browser and server.
• Fastest solution
• Issues– Supported only on latest browsers – Works only with IIS-8.0
SignalR• SignalR is a library for ASP.NET developers. Used to
develop Real Time Web Application.
• Makes use of Push Technology.
• Provides Abstraction over the set of transports.
• Open Source available on Github!!!
SignalR
Transport Techniques
Connections
Transport Priority
WebSockets
Server-Sent events
Forever Frame (IE hack)
Long Polling
HTML 5 transports
Comet transports
SignalR Connections
Hubs
Persistent Connection
Persistent Connection
• low-level control to manage connection.
• Contain events like “OnConnection”, “OnDisconnection”, “OnReconnection”
• We can write our own logic in these events.
Hubs
Hubs
• Provides a High-level API.
• Client calling Server.
• Server calling Clients. (All, Groups, One).
• Broadcasting messages to all connected clients.
Connection lifetime
Connection lifetime
How do I get SignalR?
Install-Package Microsoft.AspNet.SignalR
Some References
Routing is Very Important
Server Calling Client
Client Calling Server Function
DEMO