vijneedshelp has asked for the wisdom of the Perl Monks concerning the following question:

Hi friends, my question is similar to this question I'm using the simple websocket server, as in the example given here for building a simple chat broadcast server. The trouble is that the server is blocking, and I would like it to periodically (say every 10 seconds) send a message to all connected clients, rather than just sending out messages on incoming messages from a client. Is there any way to trigger periodic events so the server will do this? Any help is much appreciated
  • Comment on Sending periodic messages on a Websocket server

Replies are listed 'Best First'.
Re: Sending periodic messages on a Websocket server
by Corion (Patriarch) on Aug 08, 2014 at 05:59 UTC

    Your workaround seems sensible if you choose to stay with Net::WebSocket::Server, as that module does not provide easy integration with other event loops.

    Other frameworks like Mojolicious or Plack::App::WebSocket provide ways to also have other events like timer events getting fired. But I haven't done any websocket stuff, so I don't know how well those modules actually support your use case.

Re: Sending periodic messages on a Websocket server
by vijneedshelp (Initiate) on Aug 08, 2014 at 00:51 UTC
    I found a simple workaround, although I'm not sure if it's the best solution. One of the events that can be triggered by the Websocket server is on_pong. Furthermore, if you set silence_max when creating the Websocket server, it periodically pings all clients, waiting for a pong response. This pong can then be used to trigger a message to all clients.
Re: Sending periodic messages on a Websocket server
by bulrush (Scribe) on Aug 09, 2014 at 11:56 UTC
    We're going to need very basic code that you have, and errors, showing clearly what the error is and where it happens.

    If the server is blocking a protocol or port, ask the sysadmin to unblock it. There are several firewalls for Linux, iptables is only one. (I'm just learning to admin and setup Ubuntu.)

    What is the OS name and version of the server?

    Perl 5.8.8 on Redhat Linux RHEL 5.5.56 (64-bit)