use strict; use warnings; use utf8; use Amon2::Lite; use Digest::MD5 (); print "PID: $$\n"; get '/' => sub { my $c = shift; return $c->render('index.tt'); }; my $clients = {}; any '/echo2' => sub { my ($c) = @_; my $id = Digest::SHA1::sha1_hex(rand() . $$ . {} . time); $c->websocket(sub { my $ws = shift; $clients->{$id} = $ws; $ws->on_receive_message(sub { my ($c, $message) = @_; for (keys %$clients) { $clients->{$_}->send_message( "MSG: $message" ); } }); $ws->on_eof(sub { my ($c) = @_; delete $clients->{$id}; }); $ws->on_error(sub { my ($c) = @_; delete $clients->{$id}; }); }); }; # load plugins __PACKAGE__->load_plugin('Web::WebSocket'); __PACKAGE__->enable_middleware('AccessLog'); __PACKAGE__->enable_middleware('Lint'); __PACKAGE__->to_app(handle_static => 1); __DATA__ @@ index.tt WS

WS