Post your best Lua script examples here

User avatar
By amadeus84
#42582 Say I have a server

srv=net.createServer(net.TCP, 28800); -- disconnect after 8 hrs.

srv:listen(port,
function(conn)
onConnect(conn);
-- conn:on("connection",onConnect); -- for some reason this does not get executed
conn:on("reconnection",onConnect);
conn:on("receive",processRequest);
conn:on("disconnection",
function(c)
print("disconnected")
end);
end);

and various clients can connect to the esp and turn pins on/off (in the processRequest() function).
Once a pin has been turned on/off, I send back a message to inform the client that made that request about the new state of the pin. That works fine, but I want to broadcast this to ALL the clients that might be connected at the time. I can use MQTT for that, but the clients don't speak MQTT. So how can I broadcast a message from esp to all the clients connected to it?

Thanks!