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.

Reply via email to