Tuesday, July 8th, 2008

Legitimizing Comet with HTML 5 WebSocket

Category: Comet


  1. var conn = new WebSocket("ws://www.example.com/livedemo");
  3. conn.onopen = function(evt) { alert("Conn opened"); }
  4. conn.onread = function(evt) { alert("Read: " + evt.data); }
  5. conn.onclose = function(evt) { alert("Conn closed"); }
  7. conn.send("Hello World")

What if that code was part of an HTML standard? Would that make you feel better about Comet-style applications? Well, Michael Carter has pointed us to the HTML 5 discussions that give us WebSocket:

The HTML5 specification now offers WebSocket, a full-duplex communications channel that operates over a single socket. I have been listening closely, and in some cases contributing, to the process of ensuring that WebSocket will:

  • Seamlessly traverse firewalls and routers
  • Allow duly authorized cross-domain communication
  • Integrate well with cookie-based authentication
  • Integrate with existing HTTP load balancers
  • Be compatible with binary data

He goes on to discuss how WebSocket is not the same as a TCP socket itself, and what that means as we develop real-time applications.

Posted by Dion Almaer at 6:09 am

4.4 rating from 39 votes


Comments feed TrackBack URI

This is the best thing I have read about HTML5 to date! Thanks!

Comment by AMA3 — July 8, 2008

Nice to see more goods for HTML5.
Hope to see File I/O being a part of the html standard as well.
Looks like we might be able to make pretty powerfull application for the web by using the HTML standards.

Comment by Iumentum — July 8, 2008


But why is this in a spec for a markup language? Its got nothing to do with HTML…

Comment by Unfocused — July 8, 2008

@Unfocused: HTML5 is more than just the spec for the markup language itself. For example, look at Canvas. Yes, its an HTML tag, but most of its utility shows up as a JavaScript api. Additionally, if you look at the HTML5 spec, you’ll see that this isn’t exactly the first of its kind. There’s specification for client-side storage, history access, and cross-document messaging. HTML5 has really tried to take on more than just the markup, its about full browser compliance. While I agree with you that I think the browser requirements specification should be separate from a single markup language, HTML5 is gaining traction and I hope they milk it as much as they can!

Comment by genericallyloud — July 8, 2008

This is great though even when sockets are available (ex: Flash) you quite often toast on the Web at large. port80 = open, everything else in many cases smashed closed, no spec is going to widely change firewall settings or attitudes any time soon. I applaud the effort but let’s be honest about the big hurdle this will have to overcome.

Nevertheless it is great to see all this HTML 5 work though I will agreed with @Unfocused as the HTML 5 spec is becoming a bit too sprawling for my liking. Computing history has not been kind of specs like that, just saying…but time will tell. Specs are one thing…implementation and acceptance, that’s the key.

Comment by Thomas Powell — July 8, 2008

Yay!!! Yippie! Can cut the fat ( i mean flash ) out.

Comment by mojave — July 8, 2008

This seems pretty easy to implement right now – either using a variety of [native / hack] comet methods or a plugin like flash or java. Anybody know of one? (with this exact API, not similar)

Comment by matanlurey — July 8, 2008

HTML Socket != Comet.

Why are people saying Comet when talking about Sockets? It’s like this mysterious “Forward Slash” key.

Comment by pkenoyer — July 8, 2008


I understand the terminology is conflicting, but comet “acts” like a socket instead of a traditional http request – it allows data to be streamed to/from a source (usually a url), even though this is often emulated.

Comment by matanlurey — July 9, 2008

Leave a comment

You must be logged in to post a comment.