Skip to main content

TCP

Synopsis

Creates a server that accepts network messages over TCP connections. Supports both plain and TLS-encrypted connections, with configurable framing modes, connection management, and buffering options.

Schema

- id: <numeric>
name: <string>
description: <string>
type: tcp
tags: <string[]>
pipelines: <pipeline[]>
status: <boolean>
properties:
protocol: <string>
address: <string>
port: <numeric>
framing: <string>
pattern: <string>
line_delimiter: <string>
framing_rules:
- name: <string>
condition: <string>
pattern: <string>
max_event_bytes: <numeric>
min_raw_length: <numeric>
max_connections: <numeric>
timeout: <numeric>
max_message_size: <numeric>
reuse: <boolean>
workers: <numeric>
buffer_size: <numeric>
batch_size: <numeric>
queue:
interval: <numeric>
tls:
status: <boolean>
cert_name: <string>
key_name: <string>

Configuration

The following fields are used to define the device:

Device

FieldRequiredDefaultDescription
idYUnique identifier
nameYDevice name
descriptionN-Optional description
typeYMust be tcp
statusNtrueEnable/disable the device

Connection

FieldRequiredDefaultDescription
protocolN"tcp"Transport protocol (must be tcp)
addressN"0.0.0.0"Listen address
portYListen port

TCP

FieldRequiredDefaultDescription
framingN"delimiter"Framing mode (delimiter, octet, regex, or advanced)
patternY*-Event-breaker regex pattern; required when framing is regex
line_delimiterN"\n"Line separator for delimiter framing
max_connectionsN10000Maximum concurrent connections
timeoutN300Connection timeout in seconds
max_message_sizeN20971520Maximum message size in bytes (20MB)

* = Required when framing is regex

warning

When using delimiter framing, ensure that the line_delimiter matches the client's to prevent message parsing errors.

TLS

FieldRequiredDefaultDescription
tls.statusNfalseEnable TLS encryption
tls.cert_nameYTLS certificate file name (required if TLS enabled)
tls.key_nameYTLS private key file name (required if TLS enabled)
note

The TLS certificate and key files must be placed in the service root directory.

Advanced Configuration

To enhance performance and achieve better message handling, the following settings are used.

Performance

FieldRequiredDefaultDescription
reuseNtrueEnable socket address reuse
workersN<dynamic>Number of worker processes when reuse is enabled
buffer_sizeN1048576Network read buffer size in bytes (1MB)

Messages

FieldRequiredDefaultDescription
batch_sizeN1000Number of messages to batch before processing
queue.intervalN1Queue processing interval in seconds

Framing Rules

Ordered event-breaking rules for TCP connections, used when framing is set to advanced.

At connection open, the first min_raw_length bytes are buffered. The first rule whose condition matches the buffered bytes is selected for the lifetime of that connection. The last rule should have an empty condition to act as the unconditional fallback. All rules use regex-based event breaking.

FieldRequiredDefaultDescription
framing_rules[].nameN"rule-N"Descriptive rule name for logs
framing_rules[].conditionN-Regex matched against initial bytes to select this rule; empty = unconditional
framing_rules[].patternY-Event-breaker regex marking the start of each event
framing_rules[].max_event_bytesNmax_message_sizePer-rule event size cap in bytes; falls back to device-level max_message_size
framing_rules[].min_raw_lengthN256Minimum bytes to buffer before evaluating condition
note

Regex framing is event-start oriented: each regex match marks the beginning of a new event. Everything between consecutive matches is one complete event. The pattern must not match the empty string.

Examples

The following are commonly used configuration types.

Basic

A basic server can be easily created using "tcp" for protocol, "0.0.0.0" for address, and the default framing and timeout settings.

Creating a simple TCP server...

devices:
- id: 1
name: basic_tcp
type: tcp
properties:
port: 514

High-Volume

Performance can be enhanced using multiple workers, a larger buffer size (e.g. 4MB), a higher connection limit, and optimized batches.

Optimizing for high message volumes...

devices:
- id: 2
name: performant_tcp
type: tcp
properties:
port: 514
reuse: true
workers: 4
buffer_size: 4194304
max_connections: 20000
batch_size: 5000
queue:
interval: 2
note

The worker count is automatically capped at the number of physical cores available on the system.

Framing

A custom framing can be achieved using CRLF (i.e. "\r\n") as the message delimiter, a 5MB message size limit, and 1min connection timeout.

TCP server with custom message framing...

devices:
- id: 3
name: framed_tcp
type: tcp
properties:
port: 1514
framing: delimiter
line_delimiter: "\r\n"
max_message_size: 5242880
timeout: 60

Regex Framing

For a TCP server receiving multi-line events where all connections share the same event pattern, use framing: regex with a top-level pattern:

TCP server with regex event breaking on ISO timestamps...

devices:
- id: 5
name: regex_tcp
type: tcp
properties:
port: 1514
framing: regex
pattern: "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}"

Advanced Framing

For a TCP server receiving multi-line events from mixed sources, use framing: advanced with framing_rules to select the event-breaking pattern per connection based on the initial bytes:

TCP server with per-connection event-breaking rules...

devices:
- id: 6
name: advanced_tcp
type: tcp
properties:
port: 1514
framing: advanced
framing_rules:
- name: multiline-timestamp
condition: "^\\d{4}-"
pattern: "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}"
- name: fallback
pattern: "\\n"

Encryption

Security can be enhanced using TLS encryption, a custom certificate and key, connection limits, and an extended timeout the TLS handshake.

Securing TCP server with TLS encryption...

devices:
- id: 4
name: secure_tcp
type: tcp
properties:
port: 6514
tls:
status: true
cert_name: cert.pem
key_name: key.pem
max_connections: 5000
timeout: 120