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.
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.
10-second tutorial.
Create a WebSocket server that counts to ten, pausing briefly between each number.
#!/usr/bin/env python3
import time
for count in range(1, 11):
print(count, flush=True)
time.sleep(0.5)const ws = new WebSocket(
'ws://localhost:8080/'
);
ws.onmessage = (event) => {
console.log(`Count is: ${event.data}`);
};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.
Get websocketd
Download the executable for your platform and put it on your PATH.