dorkhub

love2d-lua-websocket

websocket client pure lua implement for love2d

flaribbit
Lua5211 forksMITupdated 4 years ago
git clone https://github.com/flaribbit/love2d-lua-websocket.gitflaribbit/love2d-lua-websocket

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.

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)
end

function love.update()
    client:update()
end

WSS connection

If you need wss connection(websocket with TLS), you can use LuaSec with this library, or just use löve-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()

more like this

Scythe

SCYTHE is a lightweight, C#-based game engine focused on modifiability and rapid iteration using Raylib.

C#50

tobira.nvim

Open the next door in your Vim journey — personalized command discovery based on your actual usage

Lua51

search

search projects, people, and tags