【发布时间】:2013-06-24 20:21:29
【问题描述】:
鉴于下面的代码,我如何从 Fu::Bar::dosomething 中通过为“/wsinit”打开的 websocket 向客户端发送消息?
package Fu;
use Mojo::Base 'Mojolicious';
sub startup
{
my $r = shift->routes;
$r->get('/')->to(controller => 'bar', action => 'init');
$r->websocket('/wsinit')->to(controller => 'bar', action => 'wsinit');
$r->get('/dosomething')->to(controller => 'bar', action => 'dosomething');
}
1;
# -- ^L
# --
package Fu::Bar;
use Mojo::Base 'Mojolicious::Controller';
sub init
{
my $self = shift;
$self->render(text => 'init');
}
sub wsinit
{
my $self = shift;
$self->app->log->debug( 'Websocket opened.' );
$self->send({json => {fu => 'bar'}});
}
sub dosomething
{
my $self = shift;
}
1;
请忽略以下多余的措辞,其目的是满足当前阻止我发布问题的 stackoverflow 的详细信息/代码要求。
【问题讨论】:
-
什么语言的代码? Perl?
标签: perl mojolicious