WebSockets
the UNIX way

Full duplex messaging between web browsers and servers

websocketd is the WebSocket daemon

It takes care of handling the WebSocket connections,
launching your programs to handle the WebSockets,
and passing messages between programs and web-browser.

It's like CGI, twenty years later, for WebSockets

Language agnostic

If you can run your program from the command line, you can write WebSocket endpoints.

No libraries required

Just read incoming text from stdin and write outgoing text to stdout.
Messaging is simple.

Avoid threading headaches

Each inbound WebSocket connection runs your program in a dedicated process.
Connections are isolated by process.

Built for the UNIX philosophy

Write programs that do one thing and do it well.
Write programs to work together.
Write programs to handle text streams,
because that is a universal interface.

If you dig that, you'll dig websocketd.

10 second tutorial

Let's create a tiny WebSocket server that counts to ten, pausing between each iteration.

Create a program in your favorite language:

  • Bash
  • Java
  • Python
  • Ruby
  • PHP
  • Perl
  • C
  • C#
  • Swift
  • Dart
  • In fact... anything!
#!/bin/bash

# Count from 1 to 10 with a sleep
for ((COUNT = 1; COUNT <= 10; COUNT++)); do
  echo $COUNT
  sleep 0.5
done

Start websocketd and tell it about your program:

$ websocketd --port=8080 my-program

Now connect to your program from JavaScript in a web-page using a WebSocket:

var ws = new WebSocket('ws://localhost:8080/');

ws.onmessage = function(event) {
  console.log('Count is: ' + event.data);
};

See... WebSocket servers are simple!

Whichever way inclined you are

I Perl

Oh, and...

Static server

Serves your static HTML, JavaScript, etc

Program routing

Route different URLs to different programs

CGI server

Dynamic generate content over HTTP too

SSL

Out-of-the-box support for serving content using HTTPS and WSS

Origin checking

Restrict which pages can make WebSocket connections

Development console

Interact with your WebSocket programs before you've built your frontend

Get it

Available for Linux, OSX, Windows, FreeBSD, OpenBSD and Solaris

websocketd is a single executable program. Easy to copy to servers.

Current version: 0.3.0

Announcements, new features, security advisories

We won't share your email address with anyone else. Pinky swear.