Aplicaciones en tiempo real con SignalR

30
Francesc Jaumot @fjaumot Co-founder at Clibb Real-time Communications with SignalR

Transcript of Aplicaciones en tiempo real con SignalR

Page 1: Aplicaciones en tiempo real con SignalR

Francesc Jaumot@fjaumotCo-founder at Clibb

Real-time Communications with SignalR

Page 2: Aplicaciones en tiempo real con SignalR

1) Introduction to the real-time web2) ASP.NET SignalR3) Building a real-time

Agenda

Page 3: Aplicaciones en tiempo real con SignalR

Without real-time

Got Data?

Got Data?

Got Data?

Here’s some data!

Got Data?

Got Data?

Got Data?ServerClient

Page 4: Aplicaciones en tiempo real con SignalR

With real-time

I do real-time, do you?

Yep!

ServerClientLet’s Party in Real-time!

Page 5: Aplicaciones en tiempo real con SignalR

Basically…

SignalR!!!

ServerClient

Page 6: Aplicaciones en tiempo real con SignalR

Introducing SignalR• Abstraction over transports• Events instead of task/async• Connection management• Broadcast or target specific client

Page 7: Aplicaciones en tiempo real con SignalR

What does SignalR do?

• Client to Server persistent connection over HTTP

• Easily build multi-user, real-time web applications

• Auto-negotiates transport

Page 8: Aplicaciones en tiempo real con SignalR

So how can SignalR know which methodology to use on both sides of the *persistent HTTP connection?

Page 9: Aplicaciones en tiempo real con SignalR

SignalR Fallback

Long Polling

Forever Frames

Server Sent Events

Web Sockets

Page 10: Aplicaciones en tiempo real con SignalR

Transport Negotiation

Let’s try Websockets!

No? How about SSE?No? Forever Frames?

Okay, then. Long Polling!

Page 11: Aplicaciones en tiempo real con SignalR

What does SignalR do?

• Allows server-to-client push and RPC• Built async to scale to 1000’s of

connections• Open Source on GitHub

Page 12: Aplicaciones en tiempo real con SignalR

SignalR Hubs

Page 13: Aplicaciones en tiempo real con SignalR

SignalR Hubs

A hub is a .NET class that inherits fromMicrosoft.AspNet.SignalR.Hub

Since Hubs are called on the client by name, the name can be customized if needed

The Clients property of a Hub class exposes dynamic properties useful for targeting specific clients

Hub classes also have virtual methods useful for responding to connected/disconnected events

Page 14: Aplicaciones en tiempo real con SignalR

Sending messages to all connected clients

Jon

Scott

BradyHub

Clients.All.doWork()

Page 15: Aplicaciones en tiempo real con SignalR

Sending messages to the calling client

Jon

Scott

BradyHub

Clients.Caller.doWork()

Page 16: Aplicaciones en tiempo real con SignalR

Sending messages to other connected clients

Jon

Scott

BradyHub

Clients.Others.doWork()

Page 17: Aplicaciones en tiempo real con SignalR

Sending messages to specific users

Jon

Scott

BradyHub

Clients.Users(“Brady”).doWork()

Page 18: Aplicaciones en tiempo real con SignalR

Demo

Page 19: Aplicaciones en tiempo real con SignalR

Microsoft /web

®

Backplane

SignalR Backplanes

Load balancing via a common transport mechanism

Load

Bala

nce

r

Page 20: Aplicaciones en tiempo real con SignalR

SignalR on the client

Page 21: Aplicaciones en tiempo real con SignalR

SignalR’s .NET Client NuGet

Page 22: Aplicaciones en tiempo real con SignalR

JavaScript Client .NET Client

SignalR JavaScript & .NET Client Parity

Page 23: Aplicaciones en tiempo real con SignalR

Using SignalR in New ASP.NET Web ApplicationsSignalR is included in the Visual Studio 2013 ASP.NET templates

NuGet

• Install the SignalR and/or SignalR JS packages

OWIN

• Wire up SignalR using OWIN in the Startup.cs file

HTML

• Include jQuery & SignalR jQuery Plugin in HTML

Hubs

• Create a SignalR Hub through which clients can communicate

Page 24: Aplicaciones en tiempo real con SignalR

Using SignalR in Existing ASP.NET Web Applications

NuGet

• Install the SignalR and/or SignalR JS packages

OWIN

• Wire up SignalR using OWIN in the Startup.cs file

HTML

• Include jQuery & SignalR jQuery Plugin in HTML

Hubs

• Create a SignalR Hub through which clients can communicate

Page 25: Aplicaciones en tiempo real con SignalR

Wire up SignalR using OWIN

Page 26: Aplicaciones en tiempo real con SignalR

Include the jQuery Scripts

Note – the order is important!

Page 27: Aplicaciones en tiempo real con SignalR

Create a Hub

Page 28: Aplicaciones en tiempo real con SignalR

Connect the client to the Hub using JavaScript

Page 29: Aplicaciones en tiempo real con SignalR

Introduction to ASP.NET MVCLighting Up Real-Time Web Communications with SignalR

And many more: Azure, mobile apps, games…

Microsoft Virtual Academy

Page 30: Aplicaciones en tiempo real con SignalR

Q&A

Francesc Jaumot@fjaumot