internet of things &.net gadgeteer & microsoft signalr mirco vanini iot with signalr...

24
Internet of Things & .NET Gadgeteer & Microsoft SignalR Mirco Vanini IoT with SignalR & .NET Gadgeteer Microsoft® MVP Windows Embedded

Upload: sierra-hansen

Post on 28-Mar-2015

228 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Internet of Things &.NET Gadgeteer & Microsoft SignalR Mirco Vanini IoT with SignalR &.NET Gadgeteer Microsoft® MVP Windows Embedded

Internet of Things & .NET Gadgeteer & Microsoft SignalRMirco Vanini

IoT with SignalR & .NET Gadgeteer

Microsoft® MVP Windows Embedded

Page 2: Internet of Things &.NET Gadgeteer & Microsoft SignalR Mirco Vanini IoT with SignalR &.NET Gadgeteer Microsoft® MVP Windows Embedded

Agenda

Perché real-time e come ?SignalRConnections and HubsClientsDemoQ&ALinks

Page 3: Internet of Things &.NET Gadgeteer & Microsoft SignalR Mirco Vanini IoT with SignalR &.NET Gadgeteer Microsoft® MVP Windows Embedded

Perché real-time e come ?

Gli utenti vogliono le ultime informazioni, ORA !

Twitter – live searches/updates Stock streamersAuctionsLive scoresReal-time notificationsInteractive gamesCollaborative appsLive user analytics

Page 4: Internet of Things &.NET Gadgeteer & Microsoft SignalR Mirco Vanini IoT with SignalR &.NET Gadgeteer Microsoft® MVP Windows Embedded

Perché real-time e come ?

HTTP is an old beast…• Never designed for real-time communications• Web is request-response• Web is stateless

HTML5 WebSockets to the rescue, right?

Extension to HTTPProvide raw sockets over HTTPFull-duplexTraverses proxies

It’s still a draft…Not every proxy server supports itNot every webserver supports itNot every browser supports itThey are raw sockets!

Page 5: Internet of Things &.NET Gadgeteer & Microsoft SignalR Mirco Vanini IoT with SignalR &.NET Gadgeteer Microsoft® MVP Windows Embedded

Perché real-time e come ?

Come implementare il real-time con HTTP:

Polling.Long Polling.Forever Frame.Server Sent Events

Page 6: Internet of Things &.NET Gadgeteer & Microsoft SignalR Mirco Vanini IoT with SignalR &.NET Gadgeteer Microsoft® MVP Windows Embedded

Perché real-time e come ?

Polling: the stubborn approach

Server

Client

Time: requests event ‘n’ seconds (fixed time)

Request

Resp

onse

delay

Twitter clients

Page 7: Internet of Things &.NET Gadgeteer & Microsoft SignalR Mirco Vanini IoT with SignalR &.NET Gadgeteer Microsoft® MVP Windows Embedded

Perché real-time e come ?

Polling

• High overhead on requests: headers and such…

• High overhead on response: same as before…

• High latency.

• Waste of bandwith.

• Waste of resources.

Page 8: Internet of Things &.NET Gadgeteer & Microsoft SignalR Mirco Vanini IoT with SignalR &.NET Gadgeteer Microsoft® MVP Windows Embedded

Perché real-time e come ?

Long Polling: the kind gentleman approach

Server

Client

Time: requests event ‘n’ seconds (variable)

Request

Resp

onse

Variable delay

Facebook chat

Page 9: Internet of Things &.NET Gadgeteer & Microsoft SignalR Mirco Vanini IoT with SignalR &.NET Gadgeteer Microsoft® MVP Windows Embedded

Perché real-time e come ?

Long Polling (Hanging GET)

• High overhead on requests: headers and such…

• High overhead on response: same as before…

• Medium latency.• Waste less of bandwith.• Waste of resources.• Better than the previous one: less

requests

Page 10: Internet of Things &.NET Gadgeteer & Microsoft SignalR Mirco Vanini IoT with SignalR &.NET Gadgeteer Microsoft® MVP Windows Embedded

Perché real-time e come ?

HTTP/1.1 200 OKContent-Type: text/plainTransfer-Encoding: chunked

• Server tells client that response is chuncked• Client keeps connection open untill server closes

it• Server pushes data to the client followed by \0• Consumes server threads

Client

<script>eval("... ")</script>\0

<script>eval("... ")</script>\0

ServerForever Frame

Page 11: Internet of Things &.NET Gadgeteer & Microsoft SignalR Mirco Vanini IoT with SignalR &.NET Gadgeteer Microsoft® MVP Windows Embedded

Perché real-time e come ?

Server-Sent Events

• Server-Sent Events (SSE) are a standard describing how servers can initiate data transmission towards clients once an initial client connection has been established. They are commonly used to send message updates or continuous data streams to a browser client and designed to enhance native, cross-browser streaming through a JavaScript API called EventSource, through which a client requests a particular URL in order to receive an event stream.

Stream Updates with Server-Sent Events

Page 12: Internet of Things &.NET Gadgeteer & Microsoft SignalR Mirco Vanini IoT with SignalR &.NET Gadgeteer Microsoft® MVP Windows Embedded

Real-time: How to survive ?

So many options and a big Headache !

Page 13: Internet of Things &.NET Gadgeteer & Microsoft SignalR Mirco Vanini IoT with SignalR &.NET Gadgeteer Microsoft® MVP Windows Embedded

SignalR

• Persistent Connection Abstraction communication library.

• Abstracts protocol and transfer (choses the best one).

• A single programming model (a unified development experience).

• Extremely simple to use.• Server-side it can be hosted in different

«environments» (ASP.NET, console apps, windows services, etc…).

• Client-side there’s support for: Javascript clients, .NET clients, WP; provide by the community: iOS, Android.

Page 14: Internet of Things &.NET Gadgeteer & Microsoft SignalR Mirco Vanini IoT with SignalR &.NET Gadgeteer Microsoft® MVP Windows Embedded

SignalR

• Works everywhere !!!• Try WebSocket then fallback to:• Server Sent Events• Forever Frame• Long Polling

• Bet to keep the logic connection up include retry logic

• Scale out to web-farms

Page 15: Internet of Things &.NET Gadgeteer & Microsoft SignalR Mirco Vanini IoT with SignalR &.NET Gadgeteer Microsoft® MVP Windows Embedded

SignalR

• Complete rewrite of the internals for 1.0.0

• Very hight performance on a single box 100.000’s of messages per seconds

• Very low memory overhead• Full async• 1000’s of connection per server• Cross-platform: run it on OSX or Linux

with Mono• Supported part of ASP.NET family

Page 16: Internet of Things &.NET Gadgeteer & Microsoft SignalR Mirco Vanini IoT with SignalR &.NET Gadgeteer Microsoft® MVP Windows Embedded

SignalR

• Persistent Connections: «Low level» API, manages the connection and the «raw» stream of data.

• Hubs: «High level» API, provide advanced support for internal routing (calling functions on server & clients), connection and disconnection tracking, grouping etc… Automatic client proxy generation (JavaScript)

Page 17: Internet of Things &.NET Gadgeteer & Microsoft SignalR Mirco Vanini IoT with SignalR &.NET Gadgeteer Microsoft® MVP Windows Embedded

SignalR

Install-Package Microsoft.AspNet.SignalRInstall-Package Microsoft.AspNet.SignalR.Sample

Page 18: Internet of Things &.NET Gadgeteer & Microsoft SignalR Mirco Vanini IoT with SignalR &.NET Gadgeteer Microsoft® MVP Windows Embedded

SignalR packages

Core• Microsoft.AspNet.SignalR.Core: Server side components

needed to build SignalR endpoints

Meta package• Microsoft.AspNet.SignalR: - A meta package that brings in

everything you need to run it on IIS and ASP.NET

Hosts• Microsoft.AspNet.SignalR.SystemWeb - Pulls in the

required packages to host SignalR in ASP.NET (via OWIN ASP.NET host)

• Microsoft.AspNet.SignalR.Owin - OWIN* host for SignalR

* OWIN stands for “Open Web Interface for .NET” and it is a specification for the communication between .NET Web Server and Web applications.

Page 19: Internet of Things &.NET Gadgeteer & Microsoft SignalR Mirco Vanini IoT with SignalR &.NET Gadgeteer Microsoft® MVP Windows Embedded

SignalR packages

Clients• Microsoft.AspNet.SignalR.Js - Javascript client for SignalR• Microsoft.AspNet.SignalR.Client - .NET client for SignalR

(includes WinRT, Windows Phone 8 and Silverlight5 clients)

Scaleout Buses• Microsoft.AspNet.SignalR.Redis - Redis scaleout for

SignalR• Microsoft.AspNet.SignalR.ServiceBus - Service bus

scaleout for SignalR

Sample• Microsoft.AspNet.SignalR.Sample - A sample stock ticker

you can quickly and easily bring into your app to get a working sample up and running.

Page 20: Internet of Things &.NET Gadgeteer & Microsoft SignalR Mirco Vanini IoT with SignalR &.NET Gadgeteer Microsoft® MVP Windows Embedded

Demo

Web Plant MonitorPlantHubPlantMonitorPlantManager

Plant DevicePlantCommandPlantDataTcpCommandListener

Page 21: Internet of Things &.NET Gadgeteer & Microsoft SignalR Mirco Vanini IoT with SignalR &.NET Gadgeteer Microsoft® MVP Windows Embedded

Demo Data Flow

PagePage

HUB Device

Page

Send

Com

mand

data

command

22000

21000

data

up

date

Pla

intD

ata

com

mand

Page 22: Internet of Things &.NET Gadgeteer & Microsoft SignalR Mirco Vanini IoT with SignalR &.NET Gadgeteer Microsoft® MVP Windows Embedded

Q&A