Skip to content

dvv/luvit-websocket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

WebSocket for Luvit

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published