Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/flaribbit/love2d-lua-websocket
websocket client pure lua implement for love2d
https://github.com/flaribbit/love2d-lua-websocket
client love2d lua luajit luasocket websocket websocket-client
Last synced: 3 months ago
JSON representation
websocket client pure lua implement for love2d
- Host: GitHub
- URL: https://github.com/flaribbit/love2d-lua-websocket
- Owner: flaribbit
- License: mit
- Created: 2021-02-12T13:26:19.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-11-02T02:06:05.000Z (about 3 years ago)
- Last Synced: 2024-10-01T08:03:10.570Z (3 months ago)
- Topics: client, love2d, lua, luajit, luasocket, websocket, websocket-client
- Language: Lua
- Homepage:
- Size: 46.9 KB
- Stars: 37
- Watchers: 3
- Forks: 10
- Open Issues: 2
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
- awesome-love2d - love2d-lua-websocket - A simple event-driven websocket client library. (IPv4) (Networking)
README
# websocket client pure lua implement for love2d
Event-driven websocket client for love2d in pure lua, which aims to be simple and easy to use.
Not all websocket features are implemented, but it works fine. Tested with aiohttp(python) and ws(nodejs) library.
## Quick start
Just copy `websocket.lua` to your project directory, and write code as the following example.```lua
local client = require("websocket").new("127.0.0.1", 5000)
function client:onmessage(message)
print(message)
end
function client:onopen()
self:send("hello from love2d")
self:close()
end
function client:onclose(code, reason)
print("closecode: "..code..", reason: "..reason)
endfunction love.update()
client:update()
end
```## WSS connection
If you need wss connection(websocket with TLS), you can use [LuaSec](https://github.com/brunoos/luasec) with this library, or just use [löve-ws](https://github.com/holywyvern/love-ws).## API
* `websocket.new(host: string, port: int, path?: string) -> client`
* `function client:onopen()`
* `function client:onmessage(message: string)`
* `function client:onerror(error: string)`
* `function client:onclose(code: int, reason: string)`
* `client.status -> int`
* `client:send(message: string)`
* `client:close(code?: int, reason?: string)`
* `client:update()`