Hi, as far as I know there is no easy way to communicate among different processes, so I guess that example is not really intented to work with hipnotoad.
As a suggestion, take a look to Mojo::Redis module that will allow you to subscribe and publish to "keys" from and to any process (using redis memory db). In particular "Websocket example" Mojo::Redis helped me to write a mojolicious app that shares events and content among any user in a non-blocking way. Take a look at it, maybe it will help you as well. BR, El lunes, 7 de julio de 2014 06:51:13 UTC-3, Farhad Bek escribió: > > Hi, > > I would like to have chat-application, very similar to this > websocket example: > > > https://github.com/kraih/mojo/wiki/Writing-websocket-chat-using-Mojolicious-Lite > > > #!/usr/bin/env perl > use utf8; > use Mojolicious::Lite; > use DateTime; > use Mojo::JSON; > > get '/' => 'index'; > > my $clients = {}; > > websocket '/echo' => sub { > my $self = shift; > > app->log->debug(sprintf 'Client connected: %s', $self->tx); > my $id = sprintf "%s", $self->tx; > $clients->{$id} = $self->tx; > > $self->receive_message( > sub { > my ($self, $msg) = @_; > > my $json = Mojo::JSON->new; > my $dt = DateTime->now( time_zone => 'Asia/Tokyo'); > > for (keys %$clients) { > $clients->{$_}->send_message( > $json->encode({ > hms => $dt->hms, > text => $msg, > }) > ); > } > } > ); > > $self->finished( > sub { > app->log->debug('Client disconnected'); > delete $clients->{$id}; > } > ); > }; > > > But this is not working when this aplication is running under hypnotad. > > Problem is in 'global' varibale $clients where reference to client's > tx is stored. $clients is not global enough and of course not shared > between hypnotoad workers (processes). > > To solve this problem, the author of this example offered use Database or > KeyValueStore to save "reference to clients tx". > > Can anybody suggest how to do it? > > Any idea > > Thanks > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
