All Projects → dvv → luvit-websocket

dvv / luvit-websocket

Licence: MIT license
WebSocket for Luvit

Programming Languages

lua
6591 projects
c
50402 projects - #5 most used programming language
racket
414 projects

WebSocket

A library implementing Hixie and Hybi WebSocket protocol.

Usage

Server

local handle_websocket = require('websocket').handler

require('http').createServer('0.0.0.0', 8080, function (req, res)
  if req.url:sub(1, 3) == '/ws' then
    handle_websocket(req, res, function ()
      -- simple repeater
      req:on('message', function (message)
        res:send(message)
      end)
    end)
  else
    res:finish()
  end
end)
print('Open a browser, and try to create a WebSocket for ws://localhost:8080/ws')

Browser

var ws = new WebSocket('ws://localhost:8080/ws')
ws.onmessage = function (ev) {
  console.log('GOT', ev.data)
}
ws.send('foo')

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].