Please explain your taks a bit more. Anyway, LuaSocket should never be used in .lp because it will block the whole webserver during i/o operations. You should use these functions instead: https://github.com/openresty/lua-nginx-m...xsockettcp
Recently I've created a nodejs app for realtime controlling inverter in one project. It had a client and a server and all data was exchanged via websockets in two directions. Thanks to websocket it was possible because like in LM with localbus. But in this project I've noticed that this technology could simplify and improve also other communication between client and server what's normally is done by http requests and exchanging data in JSON file.
I think websockets would be useful in .lp files for:
- every client show up-to-date app state (server sends every change in config to all clients without need to refresh page by client). This also removes the need for polling some data.
- server could send something to connected clients.
- generally I think that such possiblity could help to create better and more advanced apps to LM
Another question I have:
- could you replace jQuery need from localbus?
jQuery is required for localbus, but only $.ajax, $.param and $.each functions are used. I suppose you can provide your own compatibility layer if using any other JS library.
18.12.2018, 17:35 (This post was last modified: 18.12.2018, 17:36 by buuuudzik.)
(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:
12345678910111213141516171819202122232425262728
localev = require'ev'-- create a copas webserver and start listeninglocalserver = require'websocket'.server.ev.listen
{
-- listen on port 8080port = 8080,
-- the protocols field holds-- key: protocol name-- value: callback on new connectionprotocols = {
-- this callback is called, whenever a new client connects.-- ws is a new websocket instanceecho = function(ws)
ws:on_message(function(ws,message)
ws:send(message)
end)
-- this is optionalws:on_close(function()
ws:close()
end)
end
}
}
-- use the lua-ev loopev.Loop.default:loop()