NAME
POE::Component::Client::Bayeux - Bayeux/cometd client implementation in POE
SYNOPSIS
use POE qw(Component::Client::Bayeux);
POE::Component::Client::Bayeux->spawn(
    Host => '127.0.0.1',
    Alias => 'comet',
);
POE::Session->create(
    inline_states => {
        _start => sub {
            my ($kernel, $heap) = @_[KERNEL, HEAP];
            $kernel->alias_set('my_client');
            $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);
        },
    },
);
$poe_kernel->run();
DESCRIPTION
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.
USAGE
spawn (...)
- 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).
 - session
 - 
The POE::Session object returned from an internal create() call.
 
Create a new Bayeux client. Arguments to this method:
Returns a class object with methods of interest:
POE STATES
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
TODO
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 http://svn.xantus.org/shortbus/trunk/bayeux/bayeux.html
KNOWN BUGS
No known bugs, but I'm sure you can find some.
SEE ALSO
POE, POE::Component::Server::Bayeux, POE::Component::Client::HTTP
COPYRIGHT
Copyright (c) 2008 Eric Waters and XMission LLC (http://www.xmission.com/). 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.
AUTHOR
Eric Waters <ewaters@uarc.com>