title: How do I send periodic messages to connected clients of a Websocket in Perl
body: <p>This question is similar to this one for Python:
  <a href="https://stackoverflow.com/questions/19542333/websocket-server-sending-messages-periodically-in-python">WebSocket Server sending messages periodically in python</a></p>
  
  <p>The example given for creating a WebSocket in Perl uses a small message sending service:
  <a href="http://search.cpan.org/~topaz/Net-WebSocket-Server-0.001003/lib/Net/WebSocket/Server.pm" rel="nofollow noreferrer">http://search.cpan.org/~topaz/Net-WebSocket-Server-0.001003/lib/Net/WebSocket/Server.pm</a></p>
  
  <p>The code is:</p>
  
  <pre><code>use Net::WebSocket::Server;
  
  my $origin = 'http://example.com';
  
  Net::WebSocket::Server-&gt;new(
      listen =&gt; 8080,
      on_connect =&gt; sub {
          my ($serv, $conn) = @_;
          $conn-&gt;on(
              handshake =&gt; sub {
                  my ($conn, $handshake) = @_;
                  $conn-&gt;disconnect() unless $handshake-&gt;req-&gt;origin eq $origin;
              },
              utf8 =&gt; sub {
                  my ($conn, $msg) = @_;
                  $_-&gt;send_utf8($msg) for $conn-&gt;server-&gt;connections;
              },
              binary =&gt; sub {
                  my ($conn, $msg) = @_;
                  $_-&gt;send_binary($msg) for $conn-&gt;server-&gt;connections;
              },
          );
      },
  )-&gt;start;
  </code></pre>
  
  <p>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?</p>