SitePen Support
Webtide

Introduction to Comet Session Protocol

by Michael CarterJune 21st, 2010

I’m excited that the WebSocket protocol is picking up so much steam — it’s a great abstraction for real-time web programming, and I can’t wait to see it in every browser. That will unfortunately take longer than we would like, but in the meantime we have various flash implementations of the protocol. Besides Google Chrome and Safari 5, today there are no stand-alone, proxy-aware WebSocket clients. Additionally, WebSocket is only truly a proxy-tunneling protocol when used in encrypted mode. For these reasons, I’ve authored the Comet Session Protocol, a current-day architectural drop in for WebSocket.

Quick Bullet points about CSP

  • Provides a bi-direcitonal, client <–> server stream
  • Well specified
  • Works in all browsers without plugins
  • Traverses all intermediaries for http and https (proxies, firewalls, anti-virus, etc.)
  • Architectural WebSocket drop-in for older browsers

The protocol specification describes how a client and server can establish a reliable, bi-directional stream on top of HTTP. The protocol is designed to be implemented in browsers with JavaScript for the client, and on top of existing HTTP implementations for the server. CSP should be thought of as a transport-level technology, similar to TCP, so client and server libraries expose a socket-like interface. For instance, in Twisted/python you would define a Protocol and Factory class in order to implement a protocol, then at run-time you would expose that protocol over TCP by calling something like:

reactor.listenTCP(MyFactory(), ...)

With the Twisted/python CSP implementation you would take the exact same steps, except at run time you would alternatively (or additionally) call something like:

reactor.listenCSP(MyFactory(), ...)

and like that your TCP-based protocol implementation is now exposed to the web. CSP is not meant to replace either TCP or WebSocket, but to co-exist with both. You might have one server that listens for all three protocols if you were targeting desktop/mobile, Chrome/Safari, and Internet Explorer.

The specification is still relatively young, but implementations of CSP have been in production for almost a year now. The best client implementation at this time is js.io; multiple server implementations exist, including csp_eventlet, csp (twisted), and js.io (runs on top of node.js).

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]
Comet Support by SitePen

Leave a Reply



Copyright 2014 Comet Daily, LLC. All Rights Reserved