11.05.2021, 20:58
(28.04.2021, 05:31)admin Wrote: You can use a WebSocket connection to read/write object values. There are built-in JavaScript libraries in LM that can be used in your app if using Cordova (https://cordova.apache.org/) instead of native Android app SDK. See this thread for more info: https://forum.logicmachine.net/showthread.php?tid=525
Hi Admin,
Let me understand.
If I am going to implement a websocket server in LM, I first create a resident script with this script under:
Do I have to change anything in this script or add something?
Code:
local copas = require'copas'
-- create a copas webserver and start listening
local server = require'websocket'.server.copas.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)
while true do
local message = ws:receive()
if message then
ws:send(message)
else
ws:close()
return
end
end
end
}
}
-- use the copas loop
copas.loop()