lipp/lua-websockets
{ "createdAt": "2012-02-23T08:57:12Z", "defaultBranch": "master", "description": "Websockets for Lua.", "fullName": "lipp/lua-websockets", "homepage": "http://lipp.github.com/lua-websockets/", "language": "Lua", "name": "lua-websockets", "pushedAt": "2022-11-14T21:32:49Z", "stargazersCount": 415, "topics": [], "updatedAt": "2025-11-09T14:54:59Z", "url": "https://github.com/lipp/lua-websockets"}Not maintained / maintainer wanted !!!!
Section titled “Not maintained / maintainer wanted !!!!”If someone wants to maintain / take ownership of this project, reach out to me (issue, email). I like Lua very much, but I don’t have enough time / resources to stay engaged with it.
This project provides Lua modules for Websocket Version 13 conformant clients and servers.

The minified version is only ~10k bytes in size.
Clients are available in three different flavours:
Servers are available as two different flavours:
A webserver is NOT part of lua-websockets. If you are looking for a feature rich webserver framework, have a look at orbit or others. It is no problem to work with a “normal” webserver and lua-websockets side by side (two processes, different ports), since websockets are not subject of the ‘Same origin policy’.
copas echo server
Section titled “copas echo server”This implements a basic echo server via Websockets protocol. Once you are connected with the server, all messages you send will be returned (‘echoed’) by the server immediately.
local copas = require'copas'
-- create a copas webserver and start listeninglocal server = require'websocket'.server.copas.listen{ -- listen on port 8080 port = 8080, -- the protocols field holds -- key: protocol name -- value: callback on new connection protocols = { -- this callback is called, whenever a new client connects. -- ws is a new websocket instance echo = function(ws) while true do local message = ws:receive() if message then ws:send(message) else ws:close() return end end end }}
-- use the copas loopcopas.loop()lua-ev echo server
Section titled “lua-ev echo server”This implements a basic echo server via Websockets protocol. Once you are connected with the server, all messages you send will be returned (‘echoed’) by the server immediately.
local ev = require'ev'
-- create a copas webserver and start listeninglocal server = require'websocket'.server.ev.listen{ -- listen on port 8080 port = 8080, -- the protocols field holds -- key: protocol name -- value: callback on new connection protocols = { -- this callback is called, whenever a new client connects. -- ws is a new websocket instance echo = function(ws) ws:on_message(function(ws,message) ws:send(message) end)
-- this is optional ws:on_close(function() ws:close() end) end }}
-- use the lua-ev loopev.Loop.default:loop()Running test-server examples
Section titled “Running test-server examples”The folder test-server contains two re-implementations of the libwebsocket test-server.c example.
cd test-serverlua test-server-ev.luacd test-serverlua test-server-copas.luaConnect to the from Javascript (e.g. chrome’s debugging console) like this:
var echoWs = new WebSocket('ws://127.0.0.1:8002','echo');Dependencies
Section titled “Dependencies”The client and server modules depend on:
- luasocket
- luabitop (if not using Lua 5.2 nor luajit)
- luasec
- copas (optionally)
- lua-ev (optionally)
Install
Section titled “Install”$ git clone git://github.com/lipp/lua-websockets.git$ cd lua-websockets$ luarocks make rockspecs/lua-websockets-scm-1.rockspecMinify
Section titled “Minify”A squishy file for squish is
provided. Creating the minified version (~10k) can be created with:
$ squish --gzipThe minifed version has be to be installed manually though.
Running tests requires:
docker build .The first run will take A WHILE.