TCP in

What are TCP-In nodes used for in Node-RED

The TCP node in Node-RED allows you to establish connections to remote TCP ports, serving as a TCP client for communication with external services or devices. Additionally, it facilitates the creation of a TCP server that can accept incoming connections. This functionality supports various applications, such as interacting with web servers or receiving data streams from IoT devices. Whether you're working on IoT projects, industrial automation, or networked systems, this node seamlessly integrates TCP/IP communication into your Node-RED workflows.

What is TCP

TCP (Transmission Control Protocol) is one of the core protocols of the Internet Protocol Suite (commonly known as TCP/IP). It is a connection-oriented protocol that provides reliable, ordered, and error-checked delivery of data packets over a network. TCP guarantees the delivery of data packets in the same order they were sent. For more information on TCP, refer to RFC 9293.

Configuring TCP-In Node

  • Type:
    • Listen on: Allows the TCP node to act as a server, listening for incoming connections.
    • Connect to: Enables the TCP node to act as a client, establishing connections to remote servers.
  • Hostname: Specifies the hostname or IP address of the remote server when using the "Connect to" type.
  • Port: Specifies the TCP port number to listen on (when using "Listen on" type) or to connect to (when using "Connect to" type).
  • Enable secure (SSL/TLS) connection: Enabling this option activates SSL/TLS for secure communication. In Node-RED we have TLS config node which allows to activate TLS secure communication, refer to TLS config node for details on configurations.
  • Output:
    • Streams of: Selecting this option will outputs the data stream received from the TCP connection as a continuous stream of messages.
    • Single: Selecting this option will outputs a single message containing the data received from the TCP connection.
  • Payloads: Stream or single message of the data you're sending/receiving:
    • buffer: Data is sent/received as a buffer object.
    • String: Data is sent/received as a string.
    • Base64 String: Data is sent/received as a Base64 String.
      • delimited by: Specify the delimiter for splitting incoming data streams. Specify the delimiter for splitting incoming data streams. Commonly, ,, \r, \n.
      • re-attach delimiter: Enabling this option will reattach the delimiter to its original place.

Note: The default TCP nodes have been removed from the Node-RED palette in the FlowFuse Cloud due to limitations in routing connections to the container running Node-RED inside the FlowFuse platform

Usecases

Communicating with Servers: The TCP-In node allows Node-RED to interact with various servers through TCP/IP communication. This enables applications such as fetching data from web servers or exchanging information with other networked services.

Integration with TCP-based Devices: Node-RED can integrate seamlessly with TCP-based devices like industrial sensors, PLCs (Programmable Logic Controllers), or custom hardware controllers. The TCP-In node enables bidirectional communication, facilitating tasks such as sending commands to devices or receiving real-time data streams.

Examples

  1. In the example flow below, we create a basic TCP server using the tcp-in node.
  1. In the example flow below, we demonstrate how to utilize the TCP-In node alongside other TCP nodes to enable bidirectional communication.

Node Documentation

Provides a choice of TCP inputs. Can either connect to a remote TCP port, or accept incoming connections.

Note: On some systems you may need root or administrator access to access ports below 1024.