18. Real Time Web
10 Client requests update from server.
Server responds immediately,
Polling whether or not there is new data.
20 Client waits X seconds.
30 GOTO 10 getNewInfo() {
function
Long $.ajax("url", function(newInfo) {
if (newInfo != null) {
Polling }
// Do something with newInfo
}); // Poll again after 30 seconds
setTimeout(getNewInfo, 30000);
Sockets }
// Begin the polling loop
getNewInfo();
19. Real Time Web
10 Client requests update from server
20 Server leaves request hanging open
Polling until there is new data, then responds
30 GOTO 10
function getNewInfo() {
Long $.ajax("url", function(newInfo) {
// Do something with newInfo
Polling // Poll again immediately
getNewInfo();
});
Sockets }
// Begin the polling loop
getNewInfo();
20. Real Time Web
10 Client opens HTTP connection with
"Upgrade: WebSockets" header;
Polling Server leaves connection open.
20 Server sends new data when available
Connection remains open
30 GOTO 20
Long // Open a socket connection
var socket = new WebSocket("url");
Polling
socket.onmessage = function(msg) {
var newInfo = msg.data;
// Do something with newInfo
Sockets }
21. Obligatory warning
Q: Can I use WebSockets in production today?
A: No – still waiting for:
Widespread browser support
Widespread network support
Platform support
36. What to do next?
Download Learn
• ASP.NET Get Involved
• Stack • Share an idea
• VS 11 Beta Overflow • Open Bugs
• SignalR • ASP.NET • My Blog
• Image Forums • @rustd
Optimizer • IIS8