Eric Waters


POE::Component::Client::Bayeux - Bayeux/cometd client implementation in POE


    use POE qw(Component::Client::Bayeux);

        Host => '',
        Alias => 'comet',

        inline_states => {
            _start => sub {
                my ($kernel, $heap) = @_[KERNEL, HEAP];

                $kernel->post('comet', 'init');
                $kernel->post('comet', 'subscribe', '/chat/demo', 'events');
                $kernel->post('comet', 'publish', '/chat/demo', {
                    user => "POE",
                    chat => "POE has joined",
                    join => JSON::XS::true,
            events => sub {
                my ($kernel, $heap, $message) = @_[KERNEL, HEAP, ARG0];

                print STDERR "Client got subscribed message:\n" . Dumper($message);



This module implements the Bayeux Protocol (1.0draft1) from the Dojo Foundation. Also called cometd, Bayeux is a low-latency routing protocol for JSON encoded events between clients and servers in a publish-subscribe model.

This is the client implementation. It is not feature complete, but works at the moment for testing a Bayeux server.


spawn (...)

    Create a new Bayeux client. Arguments to this method:

    Host (required)

    Connect to this host.

    Port (default: 80)

    Connect to this port.

    SSL (default: 0)

    Use SSL on connection

    Alias (default: 'bayeux_client')

    The POE session alias for local sessions to interact with.

    Debug (default: 0)

    Either 0 or 1, indicates level of logging.

    LogFile (default: undef)

    Logfile to write output to.

    LogStdout (default: 1)

    If false, no logger output to STDOUT.

    CrossDomain (not implemented)

    Enables cross domain protocol of messaging.

    ErrorCallback (default: none)

    Provide a coderef that will receive a message hashref of any failed messages (erorrs in protocol, or simply unhandled messages).

    Returns a class object with methods of interest:


    The POE::Session object returned from an internal create() call.


The following are states you can post to to interact with the client.

init ()

    Initializes the client, connecting to the server, and sets up long polling.

publish ($channel, $message)

    Publishes arbitrary message to the channel given. Message will have 'clientId' and 'id' fields auto-populated.

subscribe ($channel, $callback)

    Subscribes client to the channel given. Callback can either be a coderef or the name of a state in the calling session. Callback will get one arg, the message that was posted to the channel subscribed to.

unsubscribe ($channel)

    Unsubscribes from channel.

disconnect ()

    Sends a disconnect request.

reconnect ()

    Disconnect and reconnect


Lots of stuff.

The code currently implements only the long-polling transport and doesn't yet strictly follow all the directives in the protocol document


No known bugs, but I'm sure you can find some.


POE, POE::Component::Server::Bayeux, POE::Component::Client::HTTP


Copyright (c) 2008 Eric Waters and XMission LLC ( All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.


Eric Waters <>