1POE::Component::Client:U:sBearyeCuoxn(t3r)ibuted Perl DoPcOuEm:e:nCtoamtpioonnent::Client::Bayeux(3)
2
3
4
6 POE::Component::Client::Bayeux - Bayeux/cometd client implementation in
7 POE
8
10 use POE qw(Component::Client::Bayeux);
11
12 POE::Component::Client::Bayeux->spawn(
13 Host => '127.0.0.1',
14 Alias => 'comet',
15 );
16
17 POE::Session->create(
18 inline_states => {
19 _start => sub {
20 my ($kernel, $heap) = @_[KERNEL, HEAP];
21 $kernel->alias_set('my_client');
22
23 $kernel->post('comet', 'init');
24 $kernel->post('comet', 'subscribe', '/chat/demo', 'events');
25 $kernel->post('comet', 'publish', '/chat/demo', {
26 user => "POE",
27 chat => "POE has joined",
28 join => JSON::XS::true,
29 });
30 },
31 events => sub {
32 my ($kernel, $heap, $message) = @_[KERNEL, HEAP, ARG0];
33
34 print STDERR "Client got subscribed message:\n" . Dumper($message);
35 },
36 },
37 );
38
39 $poe_kernel->run();
40
42 This module implements the Bayeux Protocol (1.0draft1) from the Dojo
43 Foundation. Also called cometd, Bayeux is a low-latency routing
44 protocol for JSON encoded events between clients and servers in a
45 publish-subscribe model.
46
47 This is the client implementation. It is not feature complete, but
48 works at the moment for testing a Bayeux server.
49
51 spawn (...)
52 Create a new Bayeux client. Arguments to this method:
53
54 Host (required)
55 Connect to this host.
56
57 Port (default: 80)
58 Connect to this port.
59
60 SSL (default: 0)
61 Use SSL on connection
62
63 Alias (default: 'bayeux_client')
64 The POE session alias for local sessions to interact with.
65
66 Debug (default: 0)
67 Either 0 or 1, indicates level of logging.
68
69 LogFile (default: undef)
70 Logfile to write output to.
71
72 LogStdout (default: 1)
73 If false, no logger output to STDOUT.
74
75 CrossDomain (not implemented)
76 Enables cross domain protocol of messaging.
77
78 ErrorCallback (default: none)
79 Provide a coderef that will receive a message hashref of any
80 failed messages (erorrs in protocol, or simply unhandled
81 messages).
82
83 Returns a class object with methods of interest:
84
85 session
86 The POE::Session object returned from an internal create()
87 call.
88
90 The following are states you can post to to interact with the client.
91
92 init ()
93 Initializes the client, connecting to the server, and sets up long
94 polling.
95
96 publish ($channel, $message)
97 Publishes arbitrary message to the channel given. Message will
98 have 'clientId' and 'id' fields auto-populated.
99
100 subscribe ($channel, $callback)
101 Subscribes client to the channel given. Callback can either be a
102 coderef or the name of a state in the calling session. Callback
103 will get one arg, the message that was posted to the channel
104 subscribed to.
105
106 unsubscribe ($channel)
107 Unsubscribes from channel.
108
109 disconnect ()
110 Sends a disconnect request.
111
112 reconnect ()
113 Disconnect and reconnect
114
116 Lots of stuff.
117
118 The code currently implements only the long-polling transport and
119 doesn't yet strictly follow all the directives in the protocol document
120 http://svn.xantus.org/shortbus/trunk/bayeux/bayeux.html
121
123 No known bugs, but I'm sure you can find some.
124
126 POE, POE::Component::Server::Bayeux, POE::Component::Client::HTTP
127
129 Copyright (c) 2008 Eric Waters and XMission LLC
130 (http://www.xmission.com/). All rights reserved. This program is free
131 software; you can redistribute it and/or modify it under the same terms
132 as Perl itself.
133
134 The full text of the license can be found in the LICENSE file included
135 with this module.
136
138 Eric Waters <ewaters@uarc.com>
139
140
141
142perl v5.28.1 2019-02-11 POE::Component::Client::Bayeux(3)