{"id":13896699,"url":"https://github.com/lipp/lua-websockets","last_synced_at":"2025-04-05T06:06:50.396Z","repository":{"id":2545860,"uuid":"3523733","full_name":"lipp/lua-websockets","owner":"lipp","description":"Websockets for Lua.","archived":false,"fork":false,"pushed_at":"2022-11-14T21:32:49.000Z","size":1109,"stargazers_count":409,"open_issues_count":36,"forks_count":116,"subscribers_count":40,"default_branch":"master","last_synced_at":"2025-03-29T05:06:39.232Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://lipp.github.com/lua-websockets/","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lipp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-02-23T08:57:12.000Z","updated_at":"2025-03-26T05:29:13.000Z","dependencies_parsed_at":"2023-01-11T16:10:50.289Z","dependency_job_id":null,"html_url":"https://github.com/lipp/lua-websockets","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2Flua-websockets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2Flua-websockets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2Flua-websockets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lipp%2Flua-websockets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lipp","download_url":"https://codeload.github.com/lipp/lua-websockets/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247294536,"owners_count":20915340,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-06T18:03:05.836Z","updated_at":"2025-04-05T06:06:50.352Z","avatar_url":"https://github.com/lipp.png","language":"Lua","funding_links":[],"categories":["Lua","资源","Resources"],"sub_categories":["Network"],"readme":"# Not maintained / maintainer wanted !!!!\n\nIf 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.\n\n# About\n\nThis project provides Lua modules for [Websocket Version 13](http://tools.ietf.org/html/rfc6455) conformant clients and servers. \n[![Build Status](https://travis-ci.org/lipp/lua-websockets.svg?branch=master)](https://travis-ci.org/lipp/lua-websockets)\n[![Coverage Status](https://coveralls.io/repos/lipp/lua-websockets/badge.png?branch=add-coveralls)](https://coveralls.io/r/lipp/lua-websockets?branch=master)\n\nThe minified version is only ~10k bytes in size.\n\nClients are available in three different flavours:\n\n  - synchronous\n  - coroutine based ([copas](http://keplerproject.github.com/copas))\n  - asynchronous ([lua-ev](https://github.com/brimworks/lua-ev))\n\nServers are available as two different flavours:\n\n  - coroutine based ([copas](http://keplerproject.github.com/copas))\n  - asynchronous ([lua-ev](https://github.com/brimworks/lua-ev))\n\n\nA webserver is NOT part of lua-websockets. If you are looking for a feature rich webserver framework, have a look at [orbit](http://keplerproject.github.com/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'.\n\n# Usage\n## copas echo server\nThis 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.\n\n```lua\nlocal copas = require'copas'\n\n-- create a copas webserver and start listening\nlocal server = require'websocket'.server.copas.listen\n{\n  -- listen on port 8080\n  port = 8080,\n  -- the protocols field holds\n  --   key: protocol name\n  --   value: callback on new connection\n  protocols = {\n    -- this callback is called, whenever a new client connects.\n    -- ws is a new websocket instance\n    echo = function(ws)\n      while true do\n        local message = ws:receive()\n        if message then\n           ws:send(message)\n        else\n           ws:close()\n           return\n        end\n      end\n    end\n  }\n}\n\n-- use the copas loop\ncopas.loop()\n```\n\n## lua-ev echo server\nThis 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.\n\n```lua\nlocal ev = require'ev'\n\n-- create a copas webserver and start listening\nlocal server = require'websocket'.server.ev.listen\n{\n  -- listen on port 8080\n  port = 8080,\n  -- the protocols field holds\n  --   key: protocol name\n  --   value: callback on new connection\n  protocols = {\n    -- this callback is called, whenever a new client connects.\n    -- ws is a new websocket instance\n    echo = function(ws)\n      ws:on_message(function(ws,message)\n          ws:send(message)\n        end)\n\n      -- this is optional\n      ws:on_close(function()\n          ws:close()\n        end)\n    end\n  }\n}\n\n-- use the lua-ev loop\nev.Loop.default:loop()\n\n```\n\n## Running test-server examples\n\nThe folder test-server contains two re-implementations of the [libwebsocket](http://git.warmcat.com/cgi-bin/cgit/libwebsockets/) test-server.c example.\n\n```shell\ncd test-server\nlua test-server-ev.lua\n```\n\n```shell\ncd test-server\nlua test-server-copas.lua\n```\n\nConnect to the from Javascript (e.g. chrome's debugging console) like this:\n```Javascript\nvar echoWs = new WebSocket('ws://127.0.0.1:8002','echo');\n```\n\n# Dependencies\n\nThe client and server modules depend on:\n\n  - luasocket\n  - luabitop (if not using Lua 5.2 nor luajit)\n  - luasec\n  - copas (optionally)\n  - lua-ev (optionally)\n\n# Install\n\n```shell\n$ git clone git://github.com/lipp/lua-websockets.git\n$ cd lua-websockets\n$ luarocks make rockspecs/lua-websockets-scm-1.rockspec\n```\n\n# Minify\n\nA `squishy` file for [squish](http://matthewwild.co.uk/projects/squish/home) is\nprovided. Creating the minified version (~10k) can be created with:\n\n```sh\n$ squish --gzip\n```\n\nThe minifed version has be to be installed manually though.\n\n\n# Tests\n\nRunning tests requires:\n\n  - [busted with async test support](https://github.com/lipp/busted)\n  - [Docker](http://www.docker.com)\n\n```shell\ndocker build .\n```\n\nThe first run will take A WHILE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flipp%2Flua-websockets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flipp%2Flua-websockets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flipp%2Flua-websockets/lists"}