So you need a websocket server, like, now

So, you need a websocket server, like, now. Well, fear no more, here comes websocketd to the rescue!

As it says

WebSockets the UNIX way Full duplex messaging between web browsers and servers

And it’s awfully simple to use. STDIN becomes your input, STDOUT is your output. In other words, any old console application can become a Websocket server.

I did my testing on the Windows Linux Subsystem (WLS). Just download the correct zip from the website (Note that you also get the executable for Windows, but for WLS you need the 64-bit Linux variant).

Then I did

Terminal window
sudo-apt-get install fortune cowsay

and adapted the example bash script from the websocketd website a little bit:

for ((COUNT = 1; COUNT <= 10; COUNT++)); do
fortune | cowsay
sleep 2

Just note that if you use an editor in Windows, you will have to make sure that your line endings are UNIX-style (in Sublime e.g. View->Line Endings->Unix).

What is presented as a bit of a joke nonetheless means that you can set up a websocket server veeery quickly. Bear in mind that each connection spawns a process. That is, you have straightforward isolation, but this approach may not exactly scale to the millions of connections.


If you try this out on MS Edge, it will not work OOTB connecting to localhost. This answer on SO helped me out.