This question is similar to this one for Python: WebSocket Server sending messages periodically in python
The example given for creating a WebSocket in Perl uses a small message sending service: http://search.cpan.org/~topaz/Net-WebSocket-Server-0.001003/lib/Net/WebSocket/Server.pm
The code is:
use Net::WebSocket::Server;
my $origin = 'http://example.com';
Net::WebSocket::Server->new(
listen => 8080,
on_connect => sub {
my ($serv, $conn) = @_;
$conn->on(
handshake => sub {
my ($conn, $handshake) = @_;
$conn->disconnect() unless $handshake->req->origin eq $origin;
},
utf8 => sub {
my ($conn, $msg) = @_;
$_->send_utf8($msg) for $conn->server->connections;
},
binary => sub {
my ($conn, $msg) = @_;
$_->send_binary($msg) for $conn->server->connections;
},
);
},
)->start;
This example is event based and only sends messages to clients based on messages sent from clients. If I wanted to send a periodic message to all connected clients, what is a good way of doing that? Can I create a periodic event that triggers within the socket server, or is there a way to create a Perl client that connects to the server and sends messages, which the server then broadcasts out?