Convert Figma logo to code with AI

joewalnes logowebsocketd

Turn any program that uses STDIN/STDOUT into a WebSocket server. Like inetd, but for WebSockets.

17,129
1,011
17,129
53

Top Related Projects

22,033

Package gorilla/websocket is a fast, well-tested and widely used WebSocket implementation for Go.

21,534

Simple to use, blazing fast and thoroughly tested WebSocket client and server for Node.js

Simple, secure & standards compliant web server for the most demanding of applications

Websockify is a WebSocket to TCP proxy/bridge. This allows a browser to connect to any application/server/service.

A WebSocket Implementation for Node.JS (Draft -08 through the final RFC 6455)

60,879

Realtime application framework (Node.JS server)

Quick Overview

WebSocketd is a command-line tool that turns any program that uses STDIN/STDOUT into a WebSocket server. It allows you to create WebSocket-based services using any programming language, making it easy to build real-time web applications without the need for complex WebSocket libraries.

Pros

  • Language-agnostic: Works with any programming language that can read from STDIN and write to STDOUT
  • Simple to use: Minimal setup required, making it easy for developers to create WebSocket servers quickly
  • Lightweight: Small footprint and efficient resource usage
  • Versatile: Can be used for a wide range of applications, from simple chat systems to complex real-time data streaming

Cons

  • Limited control: May not provide fine-grained control over WebSocket connections compared to dedicated WebSocket libraries
  • Potential security risks: Care must be taken to properly secure and validate input from WebSocket clients
  • Performance limitations: May not be suitable for high-performance applications with a large number of concurrent connections
  • Debugging challenges: Troubleshooting issues can be more difficult compared to using native WebSocket implementations

Getting Started

  1. Install WebSocketd:

    # On macOS using Homebrew
    brew install websocketd
    
    # On Linux, download the appropriate binary from the GitHub releases page
    
  2. Create a simple script (e.g., counter.sh):

    #!/bin/bash
    count=0
    while true; do
      echo $count
      count=$((count + 1))
      sleep 1
    done
    
  3. Make the script executable:

    chmod +x counter.sh
    
  4. Start the WebSocket server:

    websocketd --port=8080 ./counter.sh
    
  5. Connect to the WebSocket server using JavaScript in a web page:

    <script>
      var ws = new WebSocket('ws://localhost:8080/');
      ws.onmessage = function(event) {
        console.log('Count:', event.data);
      };
    </script>
    

This example creates a simple WebSocket server that sends an incrementing counter to connected clients every second.

Competitor Comparisons

22,033

Package gorilla/websocket is a fast, well-tested and widely used WebSocket implementation for Go.

Pros of gorilla/websocket

  • More flexible and customizable WebSocket implementation
  • Better performance and lower memory footprint
  • Supports both client and server-side WebSocket connections

Cons of gorilla/websocket

  • Requires more coding and setup compared to websocketd
  • Less suitable for quick prototyping or simple use cases
  • Steeper learning curve for beginners

Code Comparison

websocketd:

websocketd --port=8080 ./my_command.sh

gorilla/websocket:

http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
    conn, _ := upgrader.Upgrade(w, r, nil)
    // Handle WebSocket connection
})
http.ListenAndServe(":8080", nil)

websocketd is designed for simplicity, allowing you to create WebSocket servers from any command-line script or executable. It's ideal for quick prototyping and simple use cases. On the other hand, gorilla/websocket is a more comprehensive WebSocket implementation for Go, offering greater flexibility and control over WebSocket connections. It's better suited for complex applications and scenarios requiring fine-tuned performance.

While websocketd excels in ease of use and rapid deployment, gorilla/websocket provides a more robust foundation for building scalable WebSocket-based applications. The choice between the two depends on the specific requirements of your project and your familiarity with Go programming.

21,534

Simple to use, blazing fast and thoroughly tested WebSocket client and server for Node.js

Pros of ws

  • More flexible and customizable for complex WebSocket applications
  • Actively maintained with frequent updates and improvements
  • Supports both server and client-side WebSocket implementations

Cons of ws

  • Requires more setup and configuration for basic use cases
  • Steeper learning curve for developers new to WebSockets
  • May be overkill for simple command-line to WebSocket scenarios

Code Comparison

websocketd:

websocketd --port=8080 ./my_program.sh

ws:

const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 8080 });

wss.on('connection', function connection(ws) {
  ws.on('message', function incoming(message) {
    console.log('received: %s', message);
  });
});

Summary

websocketd is a simple tool that turns any command-line program into a WebSocket server, making it ideal for quick prototyping and simple use cases. It requires minimal setup and is easy to use for developers with limited WebSocket experience.

ws, on the other hand, is a more comprehensive WebSocket library for Node.js. It offers greater flexibility and control over WebSocket connections, making it suitable for complex applications. However, it requires more code and configuration to achieve the same basic functionality as websocketd.

Choose websocketd for quick, simple WebSocket servers based on command-line programs, and ws for more advanced, customizable WebSocket applications in Node.js environments.

Simple, secure & standards compliant web server for the most demanding of applications

Pros of uWebSockets

  • Higher performance and scalability, capable of handling millions of concurrent WebSocket connections
  • Lower memory footprint and CPU usage
  • Supports both WebSocket and HTTP protocols in a single library

Cons of uWebSockets

  • More complex to use and integrate, requiring C++ knowledge
  • Less straightforward for simple use cases or rapid prototyping
  • May require additional setup and configuration for certain features

Code Comparison

websocketd:

websocketd --port=8080 ./my_program.sh

uWebSockets:

#include <uwebsockets/App.h>

int main() {
    uWS::App().ws<PerSocketData>("/*", {
        .message = [](auto *ws, std::string_view message, uWS::OpCode opCode) {
            ws->send(message, opCode);
        }
    }).listen(8080, [](auto *listen_socket) {
        if (listen_socket) {
            std::cout << "Listening on port " << 8080 << std::endl;
        }
    }).run();
}

websocketd is designed for simplicity and ease of use, allowing quick setup of WebSocket servers using any executable as the backend. It's ideal for prototyping and simple applications but may lack advanced features and scalability.

uWebSockets, on the other hand, offers high performance and scalability, making it suitable for large-scale applications. However, it requires more programming knowledge and setup, which may be overkill for simpler projects.

Websockify is a WebSocket to TCP proxy/bridge. This allows a browser to connect to any application/server/service.

Pros of websockify

  • Specifically designed for VNC over WebSockets, making it ideal for remote desktop applications
  • Supports SSL/TLS encryption out of the box
  • Can act as a standalone proxy server, offering more flexibility in deployment

Cons of websockify

  • More complex setup and configuration compared to websocketd
  • Limited to TCP connections, while websocketd supports various types of programs

Code comparison

websockify:

websockify.WebSocketProxy(
    listen_host='',
    listen_port=8080,
    target_host="localhost",
    target_port=5900,
    ssl_target=False
)

websocketd:

websocketd --port=8080 ./my_program.sh

Summary

websockify is a specialized tool for VNC over WebSockets, offering built-in encryption and standalone proxy capabilities. It's more complex but provides targeted functionality for remote desktop applications. websocketd, on the other hand, is a simpler, more versatile tool that can turn any program or script into a WebSocket server. The choice between them depends on the specific use case and desired level of customization.

A WebSocket Implementation for Node.JS (Draft -08 through the final RFC 6455)

Pros of WebSocket-Node

  • More comprehensive WebSocket implementation with support for various WebSocket versions and extensions
  • Offers both client and server-side WebSocket functionality
  • Provides a robust API for handling WebSocket connections and events

Cons of WebSocket-Node

  • Requires more setup and configuration compared to websocketd's simplicity
  • May have a steeper learning curve for developers new to WebSocket programming
  • Lacks the ability to directly execute command-line programs as WebSocket servers

Code Comparison

websocketd:

websocketd --port=8080 ./my_program.sh

WebSocket-Node:

const WebSocketServer = require('websocket').server;
const http = require('http');

const server = http.createServer();
server.listen(8080);

const wsServer = new WebSocketServer({
    httpServer: server
});

websocketd focuses on simplicity and ease of use, allowing developers to quickly turn any command-line program into a WebSocket server. WebSocket-Node, on the other hand, provides a more feature-rich and flexible WebSocket implementation, suitable for complex applications requiring fine-grained control over WebSocket connections and behavior.

While websocketd excels in rapid prototyping and simple use cases, WebSocket-Node is better suited for larger-scale projects that need advanced WebSocket functionality and integration with existing Node.js applications.

60,879

Realtime application framework (Node.JS server)

Pros of Socket.IO

  • Provides real-time, bidirectional event-based communication
  • Supports automatic fallback to long-polling if WebSocket is unavailable
  • Offers built-in support for namespaces and rooms for organizing connections

Cons of Socket.IO

  • Heavier and more complex than pure WebSocket implementations
  • Requires both client and server-side libraries, increasing overhead
  • May introduce latency due to additional protocol layers

Code Comparison

Socket.IO (server-side):

const io = require('socket.io')(3000);
io.on('connection', (socket) => {
  console.log('A user connected');
  socket.on('chat message', (msg) => {
    io.emit('chat message', msg);
  });
});

websocketd:

#!/bin/bash
# This script will be run by websocketd
while read input
do
  echo "You said: $input"
done

Key Differences

  • Socket.IO is a full-featured library for real-time communication, while websocketd is a simple tool for creating WebSocket servers from command-line scripts
  • websocketd doesn't require any specific programming language or framework, making it more flexible for quick prototyping
  • Socket.IO provides more advanced features like rooms and namespaces, which are not available in websocketd
  • websocketd is lighter and easier to set up for simple use cases, while Socket.IO offers more robust solutions for complex applications

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

websocketd

websocketd is a small command-line tool that will wrap an existing command-line interface program, and allow it to be accessed via a WebSocket.

WebSocket-capable applications can now be built very easily. As long as you can write an executable program that reads STDIN and writes to STDOUT, you can build a WebSocket server. Do it in Python, Ruby, Perl, Bash, .NET, C, Go, PHP, Java, Clojure, Scala, Groovy, Expect, Awk, VBScript, Haskell, Lua, R, whatever! No networking libraries necessary.

-@joewalnes

Details

Upon startup, websocketd will start a WebSocket server on a specified port, and listen for connections.

Upon a connection, it will fork the appropriate process, and disconnect the process when the WebSocket connection closes (and vice-versa).

Any message sent from the WebSocket client will be piped to the process's STDIN stream, followed by a \n newline.

Any text printed by the process to STDOUT shall be sent as a WebSocket message whenever a \n newline is encountered.

Download

If you're on a Mac, you can install websocketd using Homebrew. Just run brew install websocketd. For other operating systems, or if you don't want to use Homebrew, check out the link below.

Download for Linux, OS X and Windows

Quickstart

To get started, we'll create a WebSocket endpoint that will accept connections, then send back messages, counting to 10 with 1 second pause between each one, before disconnecting.

To show how simple it is, let's do it in Bash!

count.sh:

#!/bin/bash
for ((COUNT = 1; COUNT <= 10; COUNT++)); do
  echo $COUNT
  sleep 1
done

Before turning it into a WebSocket server, let's test it from the command line. The beauty of websocketd is that servers work equally well in the command line, or in shell scripts, as they do in the server - with no modifications required.

$ chmod +x count.sh
$ ./count.sh
1
2
3
4
5
6
7
8
9
10

Now let's turn it into a WebSocket server:

$ websocketd --port=8080 ./count.sh

Finally, let's create a web-page to test it.

count.html:

<!DOCTYPE html>
<pre id="log"></pre>
<script>
  // helper function: log message to screen
  function log(msg) {
    document.getElementById('log').textContent += msg + '\n';
  }

  // setup websocket with callbacks
  var ws = new WebSocket('ws://localhost:8080/');
  ws.onopen = function() {
    log('CONNECT');
  };
  ws.onclose = function() {
    log('DISCONNECT');
  };
  ws.onmessage = function(event) {
    log('MESSAGE: ' + event.data);
  };
</script>

Open this page in your web-browser. It will even work if you open it directly from disk using a file:// URL.

More Features

  • Very simple install. Just download the single executable for Linux, Mac or Windows and run it. Minimal dependencies, no installers, no package managers, no external libraries. Suitable for development and production servers.
  • Server side scripts can access details about the WebSocket HTTP request (e.g. remote host, query parameters, cookies, path, etc) via standard CGI environment variables.
  • As well as serving websocket daemons it also includes a static file server and classic CGI server for convenience.
  • Command line help available via websocketd --help.
  • Includes WebSocket developer console to make it easy to test your scripts before you've built a JavaScript frontend.
  • Examples in many programming languages are available to help you getting started.

User Manual

More documentation in the user manual

Example Projects

Got more examples? Open a pull request.

My Other Projects

And follow @joewalnes!