listener
The listener tag allows an OGLML page to process network communications using protocols not already available. It is designed for small and simple protocols only.
The listener tag can work in two different modes: listen for incoming connections (server mode) or establish a connection (client mode). In both cases, the listener tag will listen for incoming data from the remote system.
Tasks are attached to listener tags to process data received.
Attribute |
Values |
Restrictions |
Description |
connecthost |
String |
Cannot be used if listenport is defined. |
The hostname of the remote host to connect to. |
connectport |
Integer |
Cannot be used if listenport is defined. |
The port to connect to on the remote host. |
listenport |
Integer |
Cannot be used if connectport/connect host are defined. |
The local port to listen on for new connections. |
delimitertype |
newline bytes fixedlen varlen string |
Required. |
The mechanism used to separate one incoming message from another. “newline” = read bytes until 0x0A is received “bytes” = convert value in “delimiter” attribute into a byte array and wait for those bytes. “fixedlen” = read a fixed number of bytes for each message. “string” = convert value in “delimeter” into UTF-8 bytes and wait for those bytes. “varlen” = convert value in “delimiter” to an integer “n”. The first [n] bytes of the message indicate how many bytes follow. |
delimiter |
|
May be required depending on value of delimitertype |
The data for the delimiter. Changes depending on the value of delimitertype bytes: The bytes in the message delimiter. E.g. to listen for a Carriage Return/Line Feed combination “0D0A”. fixedlen: The number of bytes in each message. String: The UTF-8 String to wait for to indicate the end of a message. E.g. “END” varlne: The number of bytes to read to determine message length. E.g. if your protocol defines a 2-byte length count at the beginning of each message, the value would be “2”. |
syncword |
|
Optional |
Defines an array of bytes to read at the start of an incoming message. E.g. for openGear protocol, the sync word would be “BAD2ACE5” |
blockingpause |
true false |
|
When processing tasks, blockingpause means that all message processing is done in the message RX Thread. This means that if a “pause” task is encountered, all RX of messages will pause too. |
buttontype |
toggle none |
|
If no button is defined, the listener is automatically started. If a button is defined, this allows the user to toggle the listener off/on. |
autostart |
true false |
|
Whether or not the listener should be automatically started. This is always true if no buttontype has been defined. |
Example
<listener autostart="true" delimitertype="newline" listenport="12345">
<task tasktype="ogscript">if (event.isMessageEvent())
{
var rec = event.getBytesAsString().trim();
var response = '';
for (var i = rec.length - 1; i >= 0; i--)
{
response += rec.charAt(i);
}
this.writeString('REVERSE: ' + response + '\n', false);
}
</task>
</listener>