2. Agenda
• “Real Time” web techniques
• What is signalR
• SignalR protocol
• Hubs
• Groups and private messages
• .Net client
• Self Hosting
• Scaleout
9. Web socket
• Actual TCP socket between server and client
• HTML5 standard
• Supported by Windows server 2012 / Windows 8
• Supported by IE10+, Chrome, Firefox, Opera and
more
10. Web socket in code
Server (C#):
public void ProcessRequest(HttpContext context)
{
HttpContext.Current.
AcceptWebSocketRequest
(new ChatWebSocketHandler());
context.Response.StatusCode
=(int)HttpStatusCode.SwitchingProtocols;
}
Client: (javascript)
var websocket = new window.WebSocket(“ws://<web socket url>”);
11. Web socket in code
Server (C#)
public class MyWebSocketHandler :
WebSocketHandler
public override void OnOpen()
public override void OnError()
public override void OnMessage(string
message)
Client (Javascript)
websocket.onopen = function () { …}
websocket.onerror = function(data) {…}
websocket.onmessage = function (event) {
12. WebSocket is not enough
• Not all servers support web sockets
• Not all network components support web sockets
• It’s API is limited
13. What do we need?
• Code once, deploy everywhere
• As cross-platform as possible
• Simple API to work with
14. What is signalR
• Open source project
• Abstraction layer over connection technique
• Can be self-hosted
• Call client methods from the server
ServerSentEvents
=
Polling
ForeverFrames
Long-Polling
WebSocket
15. So, why not WebSocket
WebSocket
• Good performance
• Strict prerequisites
• Limited API
SignalR
• Abstraction layer
• Rich API
• Supports WebSocket
21. Private messages
• You can use connection ID
• You can access a particular client by it
Clients.Client(connectionId).sendMessage(message)
22. Groups
• Part of Hub API
• Stored on client
• Not persistent
Groups.Add(Context.ConnectionId, groupName);
Clients.Group(groupName).invokeSomeClientMethod(args…);
24. Self hosting
• Three NuGet packages to install
Microsoft.Owin.Hosting
Microsoft.Owin.Host.HttpListener
Microsoft.AspNet.SignalR.Owin
• Create class with Configuration method.
• Map hub in the Configuration method
• Use the class as a type parameter to
WebApplication.Start
25. ScaleOut with Redis
• Install Redis for Linux or Clone the windows porting
• Add One line of code
GlobalHost.DependencyResolver.UseRedis(“<server>", <port>, “<password>", “<
storagekey>");
• On Windows – run redis from command line
• Your app is ready to scaleout
26. What have we seen today?
• Real time experience is more than just polling
• Using signalR can use the best available technique
• It can be self hosted
• It can scale out
• It has several clients