1
鑑於下面的代碼,我如何通過爲Fuins Bar :: dosomething中的'/ wsinit'打開的websocket向客戶端發送消息?Mojolicious 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;
請忽略以下多餘的空話其目的是滿足計算器的詳細信息/規範要求,這是目前阻止我公佈我的問題。
代碼用什麼語言? Perl的? –
是的,Perl,對不起。 – user2502652