LLP Custom Client


This example shows how to use the llp.lua module to use LLP connections directly from within a Translator script. The LLP module enables the use of LLP connections (over TCP/IP) from any module (as opposed to using a From LLP component). The  module  has just one function, llp.connect{}, to open new LLP connections.

If you have any questions please contact us at

Using the Code [top]

  • Import the LLP custom Client channel from the Builtin: Iguana Tools repository
  • Experiment with the code to find out how it works
  • Then add the module(s) to your Translator project
  • Copy the require statement from the channel and add it at the top of your script
    Note: This module uses require to return a single function
  • Adapt the code to your own requirements
  • Use the llp.connect{} function to open an LLP connection
  • Use the functions in the returned LLP (socket) connection (table) to send and receive messages:
    • s:recv() – receive LLP message
    • s:send() – send LLP message
    • s:close() – close the LLP connection
  • Interactive scripting help is included for this module

This is the github code for the main module:

How it works [top]

The LLP module has just one function, connect(), to open new LLP connections. You give it a table with the hostname (as “host”), port, and an optional “timeout” value (in seconds). If you don’t specify a timeout, all operations are given 5 seconds to complete.

local s = llp.connect{host='localhost',port=7013, timeout=20}

Connect returns a table, s, with three functions: s:send(msg) for sending messages, s:recv() for receiving, and s:close() to close the connection.

s:recv() actually returns two values: the message received and a lost-data string. If any data is sent before the LLP message-begin byte (0x0B), that data is placed in the lost-data string. Normally this string is empty, and is mainly useful for debugging LLP connections.

s:close() should be called before opening a new connection to the same location (unless you really want multiple connections). Many hosts will reject multiple connections, and most will become overwhelmed if you make too many. If s is stored globally (with a better name), it can be left open between calls to main(); verify that s is nil (if not s then…) before setting it to llp.connect().

Something like this:

local llp = require 'llp'
local s

function main(Data)
   local Success, Err = pcall(SendMessage, Data)
   if not Success then
      if s then s:close() end
      s = nil
      iguana.logInfo('Message not sent. Reason: '..Err)
      iguana.logInfo('Message sent successfully.')

function SendMessage(Msg)
   if not s then
      s = llp.connect{host='localhost',port=7013,timeout=100,live=false}
   local Ack = s:recv()

Simulation and Live Testing

If you try out the above examples yourself, you may notice that no actual LLP connections are made. The LLP module contains a simulator that accepts HL7 messages and returns ACKs. This is provided to avoid accidentally sending test data out while editing your script.

If you want to work with live LLP connections inside the editor, you can enable them by passing live=true into your llp.connect() call.

local s = llp.connect{host='localhost',port=7013, live=true}

More information [top]

Leave a Reply