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

I seem to have lost my way, and so I would like to go back and pose a general question. My use case is that I have a low volume of ZMQ published event JSON messages, and I'm looking for a way to reliably get them to a few (more than one, less than five, probably) users' web browsers in close to real time. I would prefer to avoid polling from the browsers, but I'm staying open minded. Two way communication would be nice, but I can handle communication from the browser back to the server with standard HTTP if necessary.

I would prefer not post any code (I tried that a couple of weeks ago without success) and instead ask for thoughts on the general approach, since I fear I have gone off track at some point. I'm happy to describe my immediate difficulties in comments - I just don't want to distract away from the more general inquiry.

  • Comment on recommended approach to publish asynch messages to web browser

Replies are listed 'Best First'.
Re: recommended approach to publish asynch messages to web browser
by roboticus (Chancellor) on Sep 10, 2017 at 15:19 UTC

    antichef:

    I've been experimenting with Websockets lately for a project. Perhaps that would be an approach you might like? I've not used them in Perl yet. $job is using C++/Java/JavaScript/Python, so all my Websocket experience so far is in C++/Java. I notice that there's a Net::WebSocket module available on cpan, so it shouldn't be too much trouble to get going.

    I've found the server side of Websockets to be pretty simple, and though I've not written the JavaScript side, I *did* look at it while debugging some time back, and it looked pretty simple. (I don't recall which (if any) JavaScript module we used on the browser side.)

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      I've definitely gotten the furthest with Net::WebSocket::Server -- but every time I start the event loop to listen for ZMQ messages, the thread effectively blocks. If I put it in the "on" "ready" section of the websocket connection, it actually works, with events going out to the browser, but the server is unable to handle additional connections and I can't handle disconnect/clean up. It could be that I'm just missing something simple, but at this point I'm suspecting that I'm missing something bigger.
Re: recommended approach to publish asynch messages to web browser
by 1nickt (Canon) on Sep 10, 2017 at 16:37 UTC
      will definitely check that out - thanks!