Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

SignalR - Realtime client/server communication (iSense)

698 views

Published on

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, JavaScript and perhaps a sprinkle of 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.

Published in: Internet
  • Be the first to comment

  • Be the first to like this

SignalR - Realtime client/server communication (iSense)

  1. 1. SignalR Realtime client/server communication Maarten Balliauw @maartenballiauw
  2. 2. R
  3. 3. Who am I? Maarten Balliauw Antwerp, Belgium Developer Advocate, JetBrains Founder, MyGet AZUG Focus on web ASP.NET MVC, Azure, SignalR, ... Former MVP Azure & ASPInsider Big passion: Azure http://blog.maartenballiauw.be @maartenballiauw
  4. 4. Agenda Why real-time & how? Meet SignalR Connections and Hubs Clients .NET Core Q&A
  5. 5. Why real-time & how?
  6. 6. Users want the latest info, now! Twitter – live searches/updates Stock tickers Auctions Live scores Real-time notifications Collaborative apps Live user analytics Online gaming / browser games … 6
  7. 7. HTTP is and old beast Never designed for real-time communications Web is request-response Web is stateless Websockets to the rescue!
  8. 8. Websockets Extension to HTTP Provide raw sockets over HTTP Full-duplex, low latency Traverses proxies But… Not every proxy server supports it Not every webserver supports it Not every browser supports it Some antivirus blocks it They are raw sockets! (protocol: up to you) http://websocketstest.com/
  9. 9. Forever Frame 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 HTTP/1.1 200 OK Content-Type: text/plain Transfer-Encoding: chunked <script>eval("... ")</script>0 <script>eval("... ")</script>0
  10. 10. Periodic polling Poll from time to time using Ajax Delay in communications due to polling interval Wastes bandwidth & latency  Polling interval
  11. 11. Long polling Poll but don’t respond until there’s data Poll again after data received or after the connection times out Consumes server threads & connection resources 
  12. 12. Options! Forever Frame Periodic polling Long polling Websockets (Server-Sent events)
  13. 13. SignalR
  14. 14. SignalR Three-in-one! “Persistent” client/server connection over best transport Connection negotiation Abstracts away the transport Provides just one programming model http://github.com/signalr/signalr - open source C#, JavaScript, UWP https://github.com/aspnet/signalr - new .NET Core version
  15. 15. Hello, SignalR DEMO
  16. 16. 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 not in my code) SignalR decides on transport mechanism used based on client + server
  17. 17. Connections and Hubs
  18. 18. Two programming models PERSISTENT CONNECTION Can communicate with 1..N clients Requires a route to be defined Limited to sending messages You define the “protocol” HUB Abstraction over PersistentConnection Can communicate with 1..N clients Route automatically mapped (/signalr/hubs) Can send messages and call methods SignalR defines the protocol
  19. 19. Hello, Hubs DEMO
  20. 20. 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://shootr.signalr.net/
  21. 21. Clients
  22. 22. So far we have used... On the server side Host in any ASP.NET application (SignalR.Server) On the client side JavaScript (SignalR.JS) But there’s more…
  23. 23. Connecting to SignalR DEMO
  24. 24. There is more! On the server side Host in any ASP.NET application (SignalR.Server) or using self-hosting (OWIN based) Host on Azure Scale out (Redis, Azure Service Bus) (I did a NodeJS server as well, but don’t use it in production) On the client side JavaScript (SignalR.JS), Angular (AngularJs.SignalR.Hub) Any .NET client (SignalR.Client) UWP iOS Android
  25. 25. DeckCast DEMO
  26. 26. .NET Core
  27. 27. ASP.NET Core Sockets SignalR in the ASP.NET Core world Improvements based on SignalR learnings: No more jQuery No more iframe transport No more message replay after reconnect (memory usage, performance) No more Hub-state (I did not talk about this “ViewState” because it’s evil) Endpoint per Hub (/signalr/hubs  /signalr/...) Scale-out now becomes scale-out (and not sending all messages everywhere) Sticky sessions required (sad )
  28. 28. ASP.NET Core Sockets New features: Cross-platform (including things like RaspberryPi) Binary data support (think sending images etc.) Host-agnostic (HTTP works but also TCP/UDP/... sockets) Protocol data format pluggable (JSON, protobuf, ...) TypeScript client ...
  29. 29. Demo? Will leave this one for you... Under development! https://github.com/aspnet/signalr Preview release mid-year Release later this year
  30. 30. Conclusion
  31. 31. 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
  32. 32. Thank you! http://blog.maartenballiauw.be @maartenballiauw

×