我正在玩Mojolicious和websockets.我想将服务器上多个外部命令的输出发送到网页.我没有连接和接收消息的问题,但我也想将消息发送回服务器以停止外部命令,同时让其他人继续将消息发送回客户端.我还希望一旦退出就停止检查外部命令.
外部命令只是一个单行程序,每隔几秒就会发出一个整数.我有两个websockets显示单独的divs中的数字.单击任一停止按钮发送消息,但这是我需要弄清楚如何关闭该websocket(并且只有websocket)并关闭外部命令的地方.
当我连接websocket时,我运行外部命令并设置a Mojo::IOLoop->recurring来检查是否有输出.
当我想要停止时,我认为我应该调用Mojo::IOLoop->remove($id),但这似乎并没有完全删除它,我收到错误信息,如Mojo::Reactor::Poll: Timer failed: Can't call method "is_websocket" on an undefined value.
如果我调用finish控制器对象来关闭websocket,它似乎会停止一切.
我将整个Mojolicious :: Lite应用程序作为一个要点,但这里是我的部分
use feature qw(signatures);
no warnings qw(experimental::signatures);
## other boilerplate redacted
websocket '/find' => sub ( $c ) {
state $loop = Mojo::IOLoop->singleton;
app->log->debug( "websocket for find" );
$c->inactivity_timeout( 50 );
my $id;
$c->on( message => sub ( $ws, $message ) {
my $json = decode_json( $message );
my $command = …Run Code Online (Sandbox Code Playgroud)