use Cro::HTTP::Router; use Cro::HTTP::Server; use Cro::HTTP::Router::WebSocket; my $application = route { get -> { web-socket -> $incoming { supply { my Bool $Running; multi sub process-command( "RUN" ) { True, ( $Running ?? "Already running" !! "Starting to run…" ); } multi sub process-command( "STOP" ) { False, ( $Running ?? "Stopping…" !! "Not running" ); } multi sub process-command( $command ) { $Running, "Unknown command: $command"; } emit "Connected… RUN|STOP\n" ~ "Service is { $Running ?? "already" !! "not" } running"; whenever $incoming -> $message { my $command = await $message.body-text; say "Command: $command"; ($Running, my $answer) = process-command( $command ); emit $answer; } } } } } my Cro::Service $service = Cro::HTTP::Server.new( :host, :port<8080>, :$application ); $service.start; say "Started"; react whenever signal(SIGINT) { say "Killed"; $service.stop; exit; }