Using Lua Sockets with Helm

Helm installs the LuaSocket library for TCP/IP communications.  You can follow the examples and reference there to connect to TCP and UDP devices.

Helm scripts run as part of the main Windows “event loop”, so while a script is running the user interface will be unresponsive.  You cannot just wait for an incoming message in a script –  instead you’ll need to check regularly for new messages. This is called “polling”, and Helm’s PeriodicTimer component makes this easy. It’s in the Parts Bin category  “Broadcast Devices/Other”.

The important properties of Periodic Timers are the Interval (how often they run, in milliseconds), the Enabled state and the OnTimer script.

For example, to check for incoming TCP messages on a socket you could use an OnTimer script like this

sock:settimeout(0) -- we'll return immediately if there's no message
local line, err = sock:receive() -- receive the line
if line then
  H.LABEL_1.Text = line -- or whatever you need to do with the message.
end

The example panel attached shows a HELM implementation of a simple TCP server and client. The server’s PeriodicTim listens to messages from multiple clients, and when it receives a message, reverses it and sends it back.  The client’s PeriodicTimer detects the received message and displays it.