Skip to main content

TCP Client

Connect to a TCP server and send/receive data streams.

tcp-client
input v1.0.0

Connect to a TCP server and exchange data. Supports auto-reconnect, configurable timeout, and bidirectional communication — send data via input and receive responses via output.

tcp socket network client
Inputs
1
Outputs
1

Overview

The tcp-client node connects to an external TCP server and enables bidirectional communication. Use it to:

  • Communicate with PLCs - Modbus TCP, custom industrial protocols
  • Connect to network devices - Routers, switches, custom hardware
  • Stream data - Continuous data exchange with remote servers
  • Command-response protocols - Send a command, receive a reply
Bidirectional Node

This node is a client only — it connects to an existing server. Send data via the input port; received data comes out the output port. TCP provides reliable, ordered delivery with connection management.

Properties

Property Type Required Default Description
host string localhost TCP server hostname or IP address to connect to.
port number 9000 TCP server port number.
timeout number - 10 Connection timeout in seconds.
autoReconnect boolean - true Automatically reconnect to server on disconnect.
reconnectDelay number - 5000 Delay in milliseconds between reconnect attempts.

Sending & Receiving

The node manages a persistent TCP connection to the server:

Input Send to Server

Any message received on the input port is sent to the connected TCP server. msg.payload is written as-is (string or Buffer).

Output Receive from Server

Data received from the server is emitted on the output port with msg.payload containing the data.

Output Message Format

{
  "payload": "data from server",
  "_msgid": "<unique message id>"
}

Auto Reconnect

When autoReconnect is enabled (default), the node automatically re-establishes the connection if it drops. The reconnectDelay property controls how long to wait between attempts (default: 5 seconds).

Connection Lifecycle

Connect → Exchange Data → Disconnect
                                  ↓
                    Wait reconnectDelay ms
                                  ↓
                            Reconnect

Examples

Device Telemetry

Connect to a device over TCP and receive continuous telemetry readings.

TCP Telemetry Reader

Connects to a device's TCP endpoint and logs incoming telemetry to InfluxDB.

View Flow JSON
[
  &#123;
    "id": "tcp1",
    "type": "tcp-client",
    "name": "Device Telemetry",
    "host": "192.168.1.100",
    "port": 9000,
    "timeout": 10,
    "autoReconnect": true,
    "wires": [["function1"]]
  &#125;,
  &#123;
    "id": "function1",
    "type": "function",
    "name": "Parse",
    "func": "const parts = msg.payload.split(',');\nif (parts.length >= 2) &#123;\n  msg.payload = &#123; sensor: parts[0], value: parseFloat(parts[1]) &#125;;\n  return msg;\n&#125;\nreturn null;",
    "wires": [["influx1"]]
  &#125;,
  &#123;
    "id": "influx1",
    "type": "influxdb",
    "name": "Store",
    "measurement": "telemetry"
  &#125;
]

Command & Response

Send periodic commands to a TCP server and process the responses.

Command & Response

Sends a query command every 5 seconds and processes the TCP response.

View Flow JSON
[
  &#123;
    "id": "inject1",
    "type": "inject",
    "name": "Every 5s",
    "repeat": "5",
    "payload": "READ_STATUS\n",
    "wires": [["tcp2"]]
  &#125;,
  &#123;
    "id": "tcp2",
    "type": "tcp-client",
    "name": "PLC",
    "host": "192.168.1.50",
    "port": 502,
    "autoReconnect": true,
    "wires": [["function2"]]
  &#125;,
  &#123;
    "id": "function2",
    "type": "function",
    "name": "Parse Response",
    "func": "msg.payload = JSON.parse(msg.payload);\nreturn msg;",
    "wires": [["debug1"]]
  &#125;,
  &#123;
    "id": "debug1",
    "type": "debug",
    "name": "Status"
  &#125;
]

Troubleshooting

Cannot connect to server
  • Verify the server is running and listening on the configured port
  • Check firewall rules allow outbound connections on the port
  • Test with netcat: nc -v host port
  • Increase timeout if the server is slow to accept connections
Connection drops frequently
  • Enable autoReconnect to automatically re-establish the connection
  • Check for idle timeout settings on firewalls or load balancers
  • Implement keepalive messages if the protocol supports it
  • Monitor server logs for the reason connections are being closed
Data received but garbled
  • TCP may split data across multiple packets — buffer until you see a delimiter
  • Use a function node to accumulate data and split on newlines or fixed length
  • Verify encoding matches between sender and receiver
  • For binary protocols, check byte order (big-endian vs little-endian)