(18.12.2018, 16:57)admin Wrote: Why two websockets? There's one localbus socket which is local UDP broadcast, another one is server-client TCP connection.
This was only theoretically question. I don't understand where in attached code there is the websocket assignment to some port. Because in a few examples which I read always there was some address + port 8080 (probably default for websocket);
Like below:
Code:
local ev = require'ev'
-- create a copas webserver and start listening
local server = require'websocket'.server.ev.listen
{
-- listen on port 8080
port = 8080,
-- the protocols field holds
-- key: protocol name
-- value: callback on new connection
protocols = {
-- this callback is called, whenever a new client connects.
-- ws is a new websocket instance
echo = function(ws)
ws:on_message(function(ws,message)
ws:send(message)
end)
-- this is optional
ws:on_close(function()
ws:close()
end)
end
}
}
-- use the lua-ev loop
ev.Loop.default:loop()
Done is better than perfect