Скачать презентацию Real-time ASP NET with Signal R Alex Konduforov Скачать презентацию Real-time ASP NET with Signal R Alex Konduforov

SignalR_27.09.2013.pptx

  • Количество слайдов: 34

Real-time ASP. NET with Signal. R Alex Konduforov Altex. Soft Real-time ASP. NET with Signal. R Alex Konduforov Altex. Soft

Web evolution Event-based, real-time UI Partial page updates (Ajax), RIA Dynamic pages, forms Static Web evolution Event-based, real-time UI Partial page updates (Ajax), RIA Dynamic pages, forms Static HTML pages

USERS WANT THE LATEST INFO NOW! USERS WANT THE LATEST INFO NOW!

Social networks Social networks

Auctions Auctions

Stock tickers Stock tickers

Web chats Web chats

Other applications Live scores Real-time notifications Interactive games Collaborative apps Live user analytics etc. Other applications Live scores Real-time notifications Interactive games Collaborative apps Live user analytics etc.

Standard solutions Frequent Polling Long polling Server-Sent events (HTML 5) Web. Socket (HTML 5) Standard solutions Frequent Polling Long polling Server-Sent events (HTML 5) Web. Socket (HTML 5)

Polling Get updates frequently using Ajax requests Pros: --Cons: Delay in results Wastes bandwidth Polling Get updates frequently using Ajax requests Pros: --Cons: Delay in results Wastes bandwidth & latency

Long polling Similar to usual polling (Ajax requests) Request waits longer (1 -2 minutes) Long polling Similar to usual polling (Ajax requests) Request waits longer (1 -2 minutes) Pros: Lower load on server No delays Cons: Consumes server threads & connection resources

Server-Sent events HTML 5, works over HTTP Event. Source Java. Script API Content-type: text/event-stream Server-Sent events HTML 5, works over HTTP Event. Source Java. Script API Content-type: text/event-stream Pros: No need to reconnect No need in a special protocol or server implementation Cons: Works in server-t 0 -client direction

Web. Socket HTML 5, new protocol (ws: // and wss: //) on top of Web. Socket HTML 5, new protocol (ws: // and wss: //) on top of TCP Pros: Full-duplex persistent connection (both ways) Cons: Require Web Socket protocol support on client (IE 10) Require Web Socket protocol support on server (IIS 8)

What to do? Web. Socket Best solution Server-Sent events + Very good Ajax to What to do? Web. Socket Best solution Server-Sent events + Very good Ajax to send data Not supported on all browsers and server Not supported in IE (damn!) Long Polling Not so good Supported everywhere Mix Very good Do I need to implement it on my own? ? ?

Superman Signal. R to the rescue! Superman Signal. R to the rescue!

Authors Damian Edwards David Fowler Authors Damian Edwards David Fowler

What is Signal. R? Official MS technology to build real-time multi-user ASP. NET applications: What is Signal. R? Official MS technology to build real-time multi-user ASP. NET applications: http: //signalr. net/ Out-of-box solution that consists of server and client side Abstraction over the set of transports Open-source solution available on Git. Hub that can be installed via Nu. Get

Transports priority Web. Sockets Server-Sent events Forever Frame (IE hack) Long Polling Transports priority Web. Sockets Server-Sent events Forever Frame (IE hack) Long Polling

Architecture Client side (JS, . NET/Win. RT, WP, Silverlight, etc. ) Hub API Persistent. Architecture Client side (JS, . NET/Win. RT, WP, Silverlight, etc. ) Hub API Persistent. Connection API

Hubs High-level API Similar to Controller (actions, thread per call) Hubs High-level API Similar to Controller (actions, thread per call)

Supported scenarios Client calling the server Server calling clients (all, group, one) State round-tripping Supported scenarios Client calling the server Server calling clients (all, group, one) State round-tripping between client and server Binding complex objects (JSON) Detecting connect, disconnect and reconnect clients Broadcasting from outside of a Hub Async scenarios (return Task/Task to client)

Server calling the client dynamic Clients property JSON serialization Server calling the client dynamic Clients property JSON serialization

Managing Groups Add/remove connections to groups Managing Groups Add/remove connections to groups

Broadcasting from outside Notify clients from another server-side code Broadcasting from outside Notify clients from another server-side code

Java. Script client $. connection. hub connection for all hubs (url points to /signalr) Java. Script client $. connection. hub connection for all hubs (url points to /signalr) $. connection. hub. id client id for the hub connection $. connection. hub. start() starts the connection for all hubs $. connection. {hubname} access a client side hub from the generated proxy $. connection. hub. logging set to true to enable logging

Exposing methods on the client The Java. Script client can declare methods that the Exposing methods on the client The Java. Script client can declare methods that the server can invoke: my. Hub. {method} = callback declares a function the server can invoke. method - name of the client side method callback - function to execute when the server invokes the method

Java. Script example Java. Script example

DEMO DEMO

Configuring Signal. R Set in IConfiguration. Manager: Settings Description Default value Connection. Timeout amount Configuring Signal. R Set in IConfiguration. Manager: Settings Description Default value Connection. Timeout amount of time to leave a connection open (110 sec default) 110 seconds Disconnect. Timeout amount of time to wait after a connection goes away before raising the disconnect event 20 seconds Heart. Beat. Interval interval for checking the state of a connection 10 seconds Keep. Alive amount of time to wait before sending a keep alive packet over an idle connection. Set to null to disable keep alive 30 seconds

Signal. R extensibility Pluggable interfaces in Signal. R: Interface Description IMessage. Bus Message bus Signal. R extensibility Pluggable interfaces in Signal. R: Interface Description IMessage. Bus Message bus IConnection. Id. Generator Generates connection ids IAssembly. Locator Locates assemblies to find hubs in IJava. Script. Proxy. Generator Generates the client proxy for hubs IJava. Script. Minifier Allows the dynamic javascript proxy to be minified IJson. Serializer Used to serialize and deserialize outgoing/ incoming data You can even replace IDependency. Resolver

Signal. R and web farm Available now: Azure Service Bus Windows Server Service Bus Signal. R and web farm Available now: Azure Service Bus Windows Server Service Bus SQL Server Redis Coming: NService. Bus SQL QNS etc.

Signal. R over Redis Step 1 Download and install Redis as Windows service Step Signal. R over Redis Step 1 Download and install Redis as Windows service Step 2 Install-Package Signal. R. Redis Step 3

Materials https: //github. com/Signal. R http: //jabbr. net http: //www. hanselman. com/blog/Category. View. aspx? Materials https: //github. com/Signal. R http: //jabbr. net http: //www. hanselman. com/blog/Category. View. aspx? cate gory=Signal. R http: //www. asp. net/vnext/overview/signalr-andweb-sockets http: //merle-amber. blogspot. com/2012/11/real-time-aspnet -signalr. html

Thanks for listening! merle-amber. blogspot. com @konduforov 31337 Thanks for listening! merle-amber. blogspot. com @konduforov 31337