+ All Categories
Home > Technology > Comet: Making The Web a 2-Way Medium

Comet: Making The Web a 2-Way Medium

Date post: 15-Jan-2015
Category:
Upload: joe-walker
View: 8,517 times
Download: 0 times
Share this document with a friend
Description:
A talk I did at FoWA
Popular Tags:
31
Comet: Making The Web a 2-Way Medium Joe Walker, DWR Lead Developer
Transcript
Page 1: Comet: Making The Web a 2-Way Medium

Comet: Making The Web a 2-Way MediumJoe Walker, DWR Lead Developer

Page 2: Comet: Making The Web a 2-Way Medium

What is Comet?

Long lived HTTP connections

•Low latency data

•For events outside the browser

Page 3: Comet: Making The Web a 2-Way Medium

Agenda:

Use Cases

Techniques

Technologies

Demos

Page 4: Comet: Making The Web a 2-Way Medium

Why?

Ajax made individual pages interactive places to explore

More and more of the data on the web is social and therefore changing

Page 5: Comet: Making The Web a 2-Way Medium

Why?

Time people spend on a

page

Time before a page

changes

Evolution of the Web

Page 6: Comet: Making The Web a 2-Way Medium

Why?

Simply keeping a page up to date is easy: poll

But polling kills servers

Comet keeps pages up to date *efficiently*

Page 7: Comet: Making The Web a 2-Way Medium

But ...

It’s a hack - the web is biased against it

Page 8: Comet: Making The Web a 2-Way Medium

Does that stop us?

Ajax is also a hack, but that hasn’t stopped it

And Comet does work

Page 9: Comet: Making The Web a 2-Way Medium

Examples of Comet

Chat is everywhere: GMail, Meebo, Yahoo Mail, etc.

GMail uses it to update email conversations

Google Docs uses it to show you other collaborators actions

yes.com uses it to track radio station playlists

Polar Rose are using it for delayed photo recognition

GPokr is using it for online gaming

etc...

Page 10: Comet: Making The Web a 2-Way Medium

Agenda:

Use Cases

Techniques

Technologies

Demos

Page 11: Comet: Making The Web a 2-Way Medium

Client Tricks

Maximum of 2 connections per browser per host

•Coordination using window.name in the client

•or cookies using a server

•or use multi-home DNS

HTTP streaming is download only (chunked mode)

TCP connections are kept alive under HTTP 1.1

Server detection of failed connections

Page 12: Comet: Making The Web a 2-Way Medium

Client How-to: Forever Frame

Client posts an iframe which doesn’t close quickly

•Send text/plain and poll in browser (not IE)

•Send text/plain with 4k whitespace to flush IE

•Flush with a <script> tag for each data block

The iframe will need killing and restarting to avoid memory leak

But IE clicks when iframe starts

Page 13: Comet: Making The Web a 2-Way Medium

Client How-to: Long Polling

Client makes an XHR request which does not return immediately

IE disallows reading XHR.responseText until connection is closed

Although you can keep XHR frames open forever, generally you poll

Page 14: Comet: Making The Web a 2-Way Medium

Client How-to: htmlfile

‘htmlfile’ is an ActiveX control like XHR: htmlfile = new ActiveXObject("htmlfile"); htmlfile.open(); htmlfile.write("<html><iframe src='javascript:void(0)' onload='cleanup();'></iframe></html>"); htmlfile.close(); htmlfile.parentWindow.dwr = dwr;

Avoids ‘clicking’, but doesn’t work in IE/Server 2003

Not supported in Firefox, Safari, Opera, etc.

Page 15: Comet: Making The Web a 2-Way Medium

Client How-to: Callback Polling

Create <script> blocks pointing to any domain

Create new script block when last completes

Page 16: Comet: Making The Web a 2-Way Medium

Client How-to: Other Options

Mime Messaging:

•Uses Multipart Mime in HTML: x-multipart-replace

•Not in IE

•Excellent performance

Flash

•We probably have enough other options that we don’t need to get into plugins

Page 17: Comet: Making The Web a 2-Way Medium

Server Tricks

Watch out for stream-stoppers

•Apache: mod_jk

•Buggy network proxies

•Various application firewalls

Watch out for thread starvation

Page 18: Comet: Making The Web a 2-Way Medium

Agenda:

Use Cases

Techniques

Technologies

Demos

Page 19: Comet: Making The Web a 2-Way Medium

Saving you the Pain

On the Server :

•Jetty, Twisted Python, Grizzly, Lighttpd, Perbal

Event Buses

•Cometd, mod_pubsub, mod_repubsub, Lightstreamer, KnowHow, HAppS

Frameworks

•DWR, Juggernaut, Nevow

Page 20: Comet: Making The Web a 2-Way Medium

Bayeux

Standard Protocol for Interoperable Comet

Supported by:

•Cometd, Jetty, Dojo, DWR and servers in development from BEA, IBM and Sun

Page 21: Comet: Making The Web a 2-Way Medium

Bayeux on the Client via Cometd

Dojo client implementation:dojox.cometd.init(serverUrl);dojox.cometd.publish("/topic", {/* payload */});dojox.cometd.subscribe("/topic", function(){/* ... */ });

Page 22: Comet: Making The Web a 2-Way Medium

Bayeux on the Server

package dojox.cometd;

public interface Bayeux{ Client newClient(String idprefix, Listener listener);

void publish(Client fromClient, String toChannel, Object data, String msgId);

void subscribe(String toChannel, Client subscriber);

...}

Page 23: Comet: Making The Web a 2-Way Medium

DWR

Reverse Ajax == Comet + Polling + Piggyback

(It’s just a configuration option)

Allowing the server to easily manage groups of users

Page 24: Comet: Making The Web a 2-Way Medium

DWR, Reverse Ajax

DWR calling remote JavascriptCollection sessions = context.getScriptSessionsByPage(url);

ScriptProxy proxy = new ScriptProxy(sessions);proxy.addFunctionCall("updateCallers", calls);

Page 25: Comet: Making The Web a 2-Way Medium

DWR, Reverse Ajax

DWR calling remote Script.aculo.usCollection sessions = context.getScriptSessionsByPage(url);

Effect e = new Effect(sessions);e.fade("client-id");

Page 26: Comet: Making The Web a 2-Way Medium

DWR, Reverse Ajax

DWR calling remote TIBCO GICollection sessions = context.getScriptSessionsByPage(url);

Server server = GI.getServer(sessions, "appname");Button button = server.getJSXById("button", Button.class);button.setEnabled(Form.STATEDISABLED, true);

Page 27: Comet: Making The Web a 2-Way Medium

Bayeux Performance

Page 28: Comet: Making The Web a 2-Way Medium

Agenda:

Use Cases

Techniques

Technologies

Demos

Page 29: Comet: Making The Web a 2-Way Medium

Demo

http://www.webtide.com/sessionRater/

Page 30: Comet: Making The Web a 2-Way Medium

Demo

Page 31: Comet: Making The Web a 2-Way Medium

Questions?

http://cometdaily.com/http://cometd.com/

http://getahead.org/blog/joe/http://directwebremoting.org/


Recommended