TCP Client

Send data via TCP protocol

Overview

This node implements a TCP client that sends messages to a specified TCP server. It is useful for scenarios where you need to communicate with devices, services, or applications that accept TCP socket connections, such as IoT devices, custom servers, or legacy systems.

Typical use cases include:

  • Sending commands or data to a remote device over TCP.
  • Interacting with custom TCP-based APIs or protocols.
  • Testing TCP server responses by sending messages and optionally waiting for replies.

The node supports sending a message to a target host and port, with options to wait for a response, configure timeouts, specify text encoding, and control whether the connection remains open after sending.

Properties

Name Meaning
Host Target host address (e.g., IP like 127.0.0.1 or domain like server.example.com)
Port Target port number on the host (1–65535)
Message The message string to send to the TCP server
Options Collection of additional settings:
- Wait for Response Boolean flag to wait for a response from the server after sending the message
- Connection Timeout Timeout in milliseconds for establishing the TCP connection (100–60000 ms)
- Response Timeout Timeout in milliseconds to wait for a response if "Wait for Response" is enabled (100–30000 ms)
- Encoding Text encoding used for the message and response; options: UTF-8, ASCII, Base64, Hex
- Keep Connection Open Boolean flag to keep the TCP connection open after sending the message

Output

The node outputs a JSON object containing details about the TCP communication:

  • success: Indicates if the operation was successful (true/false).
  • protocol: Always "tcp".
  • host: The target host address.
  • port: The target port number.
  • message: The sent message string.
  • encoding: The text encoding used.
  • status: One of:
    • "sent_no_wait": Message sent without waiting for a response.
    • "no_response": No response received within the response timeout.
    • "response_received": Response received from the server.
    • "connection_closed": Connection closed by the server without response.
  • bytes: Number of bytes sent (based on encoding).
  • timestamp: ISO timestamp when the operation completed.
  • keepConnectionOpen: Whether the connection was kept open after sending.
  • response (optional): If a response was received, an object with:
    • data: The response string decoded using the specified encoding.
    • bytes: Number of bytes received.

The node does not output binary data directly but handles all data as encoded strings.

Dependencies

  • Requires network access to the target TCP server.
  • No external API keys or credentials are needed.
  • Uses Node.js built-in net module for TCP socket communication.
  • Configurable timeouts and encoding must be supported by the environment.

Troubleshooting

  • Connection timeout error: Occurs if the node cannot establish a TCP connection within the specified connection timeout. Check if the host and port are correct and reachable.
  • Write error: Happens if there is a problem sending the message. Verify the message content and network stability.
  • TCP Error: General socket errors such as connection refused or reset. Ensure the server is running and accepting connections.
  • No response received: If waiting for a response but none arrives before the response timeout, consider increasing the timeout or verifying the server behavior.
  • Encoding issues: If the server expects a specific encoding, ensure the encoding property matches it to avoid garbled messages.

Links and References

Discussion