renodino has asked for the wisdom of the Perl Monks concerning the following question:

I'm looking for any modules that implement Comet support (See Ajax Patterns for a more detailed definition.). SuperSearch only surfaced "comet," or HTTP server push, using POE, which isn't very enlightening.

I realize "Comet" may be just a rehash of "push", but my CPAN search didn't surface anything obvious wrt HTTP push. I'm especially interested in what HTTP headers are needed (or need to be omitted - Content-length comes to mind), so I can make the neccesary adjustments to HTTP::Daemon::Threaded to properly "flush" content so the client can get it with the XHR responseText() method. As near as I can tell, it does not use multipart/x-mixed-replace...but I could be wrong...

Any pointers much appreciated.


Perl Contrarian & SQL fanboy

Replies are listed 'Best First'.
Re: Perl modules for Comet ?
by dragonchild (Archbishop) on Feb 11, 2007 at 04:56 UTC
    You're looking for cometd, for which there are Perl implementations. It's written by the same guy who wrote the Dojo JS framework - Alex knows his stuff.

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re: Perl modules for Comet ?
by perrin (Chancellor) on Feb 10, 2007 at 20:42 UTC
    Server push is implemented in CGI.pm. It's nothing more than a couple of headers. It is not clear which modern browsers this works in.
      Yes, I've seen that (via multipart/x-mixed-replace)...but I'm under the (possibly mistaken) impression that Comet doesn't use multipart bodies ?

      The relevant term is "flush". on FF (and pretty much everywhere but IE), XmlHttpRequest.responseText will contain whatever the server has "flushed" to the client. But I can't find a precise definition of "flush": is it just the TCP I/O flush, or is it the delimiting of one part of a multipart response (per multipart/x-mixed-replace, which IE also doesn't support) ?

      I guess maybe its time to write some code and find out...


      Perl Contrarian & SQL fanboy
        As far as I've been able to find out since you posted your OP, there is no real standard for doing all this. I guess you should be able to just flush the output buffer whenever you have a chunk of data ready and let the client-side code figure out how to break up the stream in ready chunks.

        I do know that relying on multi-part bodies alone (without client-side code) does not work as well as you'd hope, and I suspect using multi-part bodies will be slightly more work to interpret by your ajax code (if they work at all) than a custom (simpler) format.

        update: if you want to do this seriously (i.e. multiple events, many clients) with perl, you probably need a special light-weight server for the event streams, if only because having a few hundred apache processes will eat your memory.