SignalR - Code, not toothpaste - UGIALT.NET

28
6/15/22 | SLIDE 1

description

SignalR. Code, not toothpaste. (or: Using SignalR for realtime client/server communication)Today’s users are interested in a rich experience where the terms client and server don’t mean a thing. They expect real-time action between both, no matter if the technology used is HTML5 websockets or something else. This session will cover SignalR and show you how it can be used to communicate in real time between the client and server, using HTML5 or not. Combine SignalR with ASP.NET MVC, jQuery and perhaps a sprinkle of Windows Azure and you’ll have an interesting, reliable and fast stack to build your real-time client-server and server-client communications. Join me on this journey between web, cloud and user. No toothpaste. Just code.

Transcript of SignalR - Code, not toothpaste - UGIALT.NET

Page 1: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 1

Page 2: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 2

www.realdolmen.com

USING SIGNALR FOR REALTIME CLIENT/SERVER COMMUNICATION

@

My name is

I’m from

I blog at

maartenballiauw

Maarten Balliauw

Belgium

http://blog.maartenballiauw.be

Page 3: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 4

WHO AM I?

Maarten Balliauw Antwerp, Belgium www.realdolmen.com Focus on web

ASP.NET MVC, PHP, Azure, SignalR, … MVP Windows Azure (formerly ASP.NET)

Co-founder of AZUG http://blog.maartenballiauw.be @maartenballiauw

Page 4: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 5

AGENDA

Why real-time & how? Meet SignalR Connections and Hubs Clients Q&A

Page 5: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 6

WHY REAL-TIME & HOW?

Page 6: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 7

USERS WANT THE LATEST INFORMATION, NOW! Twitter – live searches/updates Stock streamers Auctions Live scores New e-mail Real-time notifications Interactive games Collaborative apps Analytics of users …

Page 7: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 8

HTTP IS AN OLD BEAST…

Never designed for real-time communications Web is request-response Web is stateless

But…

HTML5 WebSockets to the rescue, right?

Page 8: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 9

HTML5 WEBSOCKETS

Extension to HTTP Provide raw sockets over HTTP Full-duplex Traverses proxies

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

Page 9: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 10

PERIODIC POLLING

Bottom line: Poll from time to time using Ajax Delay in communications due to polling interval Wastes bandwidth & latency

Polling interval

Client

Server

Fiddlerhootsuite.com

Page 10: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 11

LONG POLLING

Bottom line: Poll but don’t respond untill there’s data Poll again after data received or after the connection

times out Consumes server threads & connection resources

Client

Server

Fiddlerfacebook.com

Page 11: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 12

WHICH LEAVES US WITH 3 OPTIONS FOR REAL-TIME Periodic polling Long polling HTML5 WebSockets

Page 12: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 13

MEET SIGNALR

ARRR!

Page 13: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 15

SIGNALR?

Three-in-one! “Persistent” client/server connection over best transport Abstracts away the transport Provides just one programming model

David Fowler and Damian Edwards(two guys on the ASP.NET team)

Not an official Microsoft project (yet?) OSS project on Github, MIT licensed

http://github.com/signalr/signalr Simple to setup & just works Depends on C# (not VB.NET), .NET 4+ and

jQuery

Page 14: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 16

WHERE DO I GET IT?

* where else!

*

Page 15: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 17

HELLO, SIGNALR!

Page 16: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 18

WHAT JUST HAPPENED?

The server is broadcasting a message every few seconds

Clients are receiving messages Code looks easy No polling or whatsoever (at least in my code)

Page 17: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 19

CONNECTIONS AND HUBS

Page 18: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 20

TWO CONNECTION MODELS

PersistentConnection Can communicate

with 1..N clients Is an IHttpHandler Requires a route to be

defined Limited to sending

messages You define the

“protocol”

Hubs Can communicate

with 1..N clients Abstraction over

PersistentConnection Route automatically

mapped (/signalr/hubs)

Can send messages and call methods

SignalR defines the protocol

Page 19: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 21

HELLO, SIGNALR HUBS!

Page 20: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 22

HUBS

Hub methods can be called from client Client methods can be called from hub Target individual client Target all clients Target group of clients

http://jabbr.net

Page 21: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 23

CLIENTS

Page 22: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 24

SO FAR WE’VE USED…

On the server side: Host in any ASP.NET application (SignalR.Server)

On the client side: JavaScript (SignalR.JS)

But there’s more…

Page 23: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 25

DECKCAST

Page 24: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 26

THAT’S A LOT MORE!

On the server side: Host in any ASP.NET application (SignalR.Server) Use “SelfHost”

https://github.com/SignalR/SignalR/tree/master/SignalR.SelfHost

On the client side: JavaScript (SignalR.JS) Any .NET client (SignalR.Client) Any WP7 device (SignalR.Client.WP7) iOS Android

Is this becoming a replacement for WCF?

Page 25: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 27

CONCLUSION

SignalR is three-in-one! “Persistent” client/server connection over best transport Abstracts away the transport Provides just one programming model

Connections & Hubs Connect various clients Make the web real-time!

Page 26: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 28

RESOURCES

My blog:http://blog.maartenballiauw.be

SignalR on Github:http://github.com/signalr/signalr

SignalR on NuGet:http://www.nuget.org/packages?q=signalr

Websockets: http://github.com/signalr/signalr.websockets

Scale-out on Windows Azure: http://github.com/signalr/signalr.azure

Objective C client: https://github.com/DyKnow/SignalR-ObjC

Android client (using MonoDroid): https://github.com/SignalR/SignalR/pull/127

Page 27: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 29

Q&A

Page 28: SignalR - Code, not toothpaste - UGIALT.NET

APRIL 12, 2023 | SLIDE 30

THANK YOU FOR JOINING

@

My name is

I’m from

I blog at

maartenballiauw

Maarten Balliauw

Belgium

http://blog.maartenballiauw.be