TCP Input

Handle direct socket clients

  • TCP input services gives you the flexibility to deal with direct socket communications
  • Following are the ways you can configure a TCP input
    • DIRECT
      • Handle to the low level socket is given to the rules code, you can deal with the data transmission directly
      • Context Variable: socket - socket handle
    • FIXED PACKET SIZE
      • Platform will buffer the content till it reaches the packet size, once reached the rule will be executed
      • Context Variable: buffer - byte array
    • BUFFERED
      • Platform will buffer the entire content before it executes the rule. Typically socket clients should connect write the data and then closes, upon closing the rule will be triggered with the buffered content
      • Context Variable: buffer - byte array
    • DELIMITED
      • Platform will buffer the content until the configured delimiter occurs, once occurs, the rule will be triggered with the buffered content
      • Context Variable: content - string
    • LINE BY LINE
      • Platform will buffer the content until a carriage return or new line feed occurs (CRLF) once occurs, the rule will be triggered
      • Context Variable: content - string

Notes

Example

A simple TCP input to shuffle playing card list and reply to the socket client

if(!"shuffle".equals(content)){
    tcp.reply("Unknown command");
    return;
}

def signs = (2..10) + ['J', 'Q', 'K', 'A'];
def symbols = ['♣', '♦', '♥', '♠'];
 
def cards = [symbols, signs].combinations().collect { it.join() }
 
cards.shuffle();

tcp.reply(cards.toString() + "\n");

Related Context APIs

Inputs Context
TCP Context

Related REST APIs

Create / Update Input
Retrieve Input
List Inputs
Count All Inputs
Start Stop Restart an Input
Delete Input
Delete All Inputs