Zurück zum Ranking

joewalnes/websocketd

Gowebsocketd.com

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

websocket-serverwebsocketsproxy
Sterne-Wachstum
Sterne
17.5k
Forks
1k
Wochenwachstum
Issues
5
5k10k15k
Feb. 2013Juli 2017Jan. 2022Juli 2026
ArtefakteGo Modulesgo get github.com/joewalnes/websocketd
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, PowerShell, 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
  const ws = new WebSocket('ws://localhost:8080/');
  ws.onopen = () => {
    log('CONNECT');
  };
  ws.onclose = () => {
    log('DISCONNECT');
  };
  ws.onmessage = (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.
  • Can listen on a Unix domain socket (--unixsocket) instead of, or alongside, a TCP address — useful for exposing websocketd only to processes on the same host, e.g. behind an SSH-forwarded or reverse-proxied socket.
  • STDERR can optionally be forwarded to WebSocket clients (--passstderr), tagged alongside STDOUT as JSON so a client can tell the two apart.
  • 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!

Ähnliche Repositories
websockets/ws

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

JavaScriptnpmMIT Licensewebsocketjavascript
22.8k2.6k
vi/websocat

Command-line client for WebSockets, like netcat (or curl) for ws:// with advanced socat-like functions

Rustcrates.ioMIT Licensewebsocketswebsocket-server
8.6k326
ithewei/libhv

🔥 比libevent/libuv/asio更易用的网络库。A c/c++ network library for developing TCP/UDP/SSL/HTTP/WebSocket/MQTT/Redis client/server.

CBSD 3-Clause "New" or "Revised" Licensehttpshttp-client
github.com/ithewei/libhv/wiki
7.5k1.4k
ninenines/cowboy

Small, fast, modern HTTP server for Erlang/OTP.

ErlangISC Licenseerlanghttp
ninenines.eu
7.5k1.2k
python-websockets/websockets

Library for building WebSocket servers and clients in Python

PythonPyPIBSD 3-Clause "New" or "Revised" Licensepythonpython3
websockets.readthedocs.io
5.7k604
swoft-cloud/swoft

🚀 PHP Microservice Full Coroutine Framework

PHPPackagistApache License 2.0swoolecoroutine
swoft.org
5.5k765
boostorg/beast

HTTP and WebSocket built on Boost.Asio in C++11

C++Boost Software License 1.0boostc-plus-plus-11
boost.org/libs/beast
4.8k689
easy-swoole/easyswoole

swoole,easyswoole,swoole framework

PHPPackagistApache License 2.0swooleeasyswoole
easyswoole.com
4.8k503
sylar-yin/sylar

C++高性能分布式服务器框架,webserver,websocket server,自定义tcp_server(包含日志模块,配置模块,线程模块,协程模块,协程调度模块,io协程调度模块,hook模块,socket模块,bytearray序列化,http模块,TcpServer模块,Websocket模块,Https模块等, Smtp邮件模块, MySQL, SQLite3, ORM,Redis,Zookeeper)

C++cppdistribution
sylar.top
4.7k1k
lonng/nano

Lightweight, facility, high performance golang based game server framework

GoGo ModulesMIT Licensegolanggame
3.2k465
chronoxor/NetCoreServer

Ultra fast and low latency asynchronous socket server & client C# .NET Core library with support TCP, SSL, UDP, HTTP, HTTPS, WebSocket protocols and 10K connections problem solution

C#MIT Licenselow-latencyperformance
chronoxor.github.io/NetCoreServer
3.1k627
boazsegev/facil.io

Your high performance web application C framework

CMIT Licensewebsocket-serverhttp-protocol
facil.io
2.4k150