render page lifetime GET default.aspx GET a.jpg GET b.js client 2 server POST “message” client 1 process GET x.ashx?... process POST “ajax” Got msg? process Nope Got msg? process Nope process Got msg? process “message” polling
client • W3C draft, worked on my IETF • support (partial) in some browsers • “pub/sub” like protocol over http • also still a W3C draft • one-way, client needs extra channel for send • proxies need to know about content-type:text/event-stream websocket server sent events
msg? “message” long polling POST “message” Got msg? “message” client 2 server POST “message” client 1 GET /forever <script> display(“message”); </script> forever frame POST “message” <script> display(“message”); </script> <iframe src=“/forever”>
forever frame • Unified programming model • Deals with connectivity issues (connection slow, reconnect, disconnects) • Available for multiple types of clients • Messaging bus • Utilizes Json.NET for serialization SignalR 1.0
override Task OnDisconnected • Base class for your own connection class • Fires events when clients connect, disconnect or send data • Allows grouping of connections • Deals with “raw” (string) data: do your own serialization • Your class gets instantiated with each new http connection
API between client and server • SignalR creates a proxy between the two parties client (javascript) var chat = $.connection.chatHub; … chat.server.message(“hi!”); … chat.client.notify = function(text) { // do something with text } server class ChatHub: Hub { public void message(string text) { Clients.All.notify(text); } } proxy dynamic