An easy way to use WebSockets?

It's often (for work or for personal projects) that I need to create a real-time feature for a website. This can range from a simple notification whenever an event happens on the server of an existing website, to implementing a real-time multiplayer game or adding a feature inspired from social media websites.

Unfortunately the increase in complexity in code (Perl & JS) and architecture involved in setting up a reliable solution, very often made me forego the opportunity to use WebSockets for many of these projects, and instead resorted to http polling to keep the solution simple for the others to maintain.

So I started looking for a library with a client & server component, that would make life easier. The library would hopefully have to have the following features:

  • Automatically reconnect to the WebSockets server, after a broken connection
  • Server channels that broadcast event streams that browsers can subscribe to, like Socket.io
  • A shared data object among all connected clients, that is always kept up to date, like Firebase
  • Automatic and transparent retrieval of all missed broadcast events after a temporary disconnect
  • Perl compatibility
  • Custom authorization routines, to decide who gets to join a channel
  • Free and open source self-hosted solution, for privacy so that it can be used in companies, plus because some customers don't like paying monthly subscription fees
  • Easy to use and set-up
  • (Optionally) allow requests/responses over the WebSocket connection

I couldn't find what I was looking for, so I made the solution:

The BoardStreams library

And I also created a demo site to show some of what's possible with this library:

https://boardstreams.com

That's all. I'm curious to see if you guys think this is interesting to you at all.

1 Comment

If you only need client-side server event notifications, a less complex alternative than WebSockets might be server-sent events.

Leave a comment

About karjala

user-pic I'm a Perl developer.