Giter Club home page Giter Club logo

love2d-lua-websocket's Introduction

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.

⚠️ wss:// connection (websocket with TLS) is not supported. If you need that, you may try löve-ws.

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

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

love2d-lua-websocket's People

Contributors

flaribbit avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.