WebSockets
the UNIX way.

websocketd runs your command-line programs as WebSocket servers, so browsers can send and receive messages from them.

Language agnostic.

If you can run your program from the command line, you can make it a WebSocket endpoint.

No libraries required.

Your program reads incoming messages from stdin and writes replies to stdout.

One process per connection

Each connection runs your program in a separate process, so each client has its own program state.

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.
From program to browser

10-second tutorial.

Create a WebSocket server that counts to ten, pausing briefly between each number.

01 Write your program.
count.py
#!/usr/bin/env python3
import time

for count in range(1, 11):
    print(count, flush=True)
    time.sleep(0.5)
02 Start websocketd.
$ chmod +x count.py $ websocketd --port=8080 ./count.py
03 Connect from the browser.
const ws = new WebSocket(
  'ws://localhost:8080/'
);

ws.onmessage = (event) => {
  console.log(`Count is: ${event.data}`);
};
Each line of stdout becomes a WebSocket message.

Batteries included

Static server

Serve your HTML, JavaScript, and other files alongside your program.

Program routing

Assign different programs to different URLs to serve multiple WebSocket endpoints.

CGI server

Generate ordinary HTTP responses with your programs, too.

HTTPS and WSS

Serve encrypted HTTP and WebSocket connections with your certificate.

Origin checking

Restrict which pages can connect to your WebSocket endpoints.

Development console

Add --devconsole and exchange messages before you've built a frontend.

Explore the CLI →

Get websocketd

Download the executable for your platform and put it on your PATH.

Linux

Find a build for your architecture.

View Linux downloads ↓

macOS

Find a build for your Mac.

View macOS downloads ↓

Windows

Find a build for your PC.

View Windows downloads ↓