Skip to main content

TCP Server Transport

Listens for a TCP client. Use it when the device connects out to a server it was configured with (a 4G/GPRS module, an ESP32, a gateway), or to stand in for a device while you test a client. The Modbus TCP loopback example uses it with the Modbus TCP Server codec. TCP carries a byte stream, so a codec splits it into messages.

  • One client at a time: when a second client connects it replaces the first; both events are logged in the message list.
  • Sending without a client fails with "No active TCP connection".
  • Bind address: 0.0.0.0 (or ::) accepts connections from the network, 127.0.0.1 only from this computer. Ports below 1024 need extra privileges on Linux, and a firewall may block incoming connections.

A simulated Modbus TCP device — a TCP server on 127.0.0.1:1502 with the Modbus TCP Server codec and its data store.

Configuration reference​

Config IDtcp_server_transport
Selected byapp_transport = "tcp_server_transport"
PlatformsLinux, Windows, Android
LicensePremium

TCP server accepting single client connection

Listening Configuration:

  • Bind Address: Local listening address (supports both IPv4 and IPv6)
    • IPv4 examples:
      • 0.0.0.0 - Listen on all IPv4 network interfaces, allow any client to connect
      • 127.0.0.1 - Listen on loopback only, allow only local clients
    • IPv6 examples:
      • :: - Listen on all IPv6 network interfaces, allow any client to connect
      • ::1 - Listen on IPv6 loopback only
      • fe80::1 - Listen on specific IPv6 address
  • Bind Port: Port number the server will listen on

Operating Mode:

  • Server starts listening on the specified address and port
  • Automatically accepts client connections
  • Supports only one client at a time, new connections replace old ones
  • Automatically waits for new connections after client disconnects
SettingKeyTypeDefaultNotes
Bind Addresstcp_server_transport_bind_addressText (with presets)"0.0.0.0"Required
Porttcp_server_transport_bind_portInteger8080Required

Setting details​

Bind Address​

Presets (any other value can be entered):

ValueLabel
"0.0.0.0"0.0.0.0 (all IPv4)
"::":: (all IPv6)
"127.0.0.1"127.0.0.1 (localhost)
"::1"::1 (localhost IPv6)

Example config​

Default values as they appear in a saved configuration (for example the JSON block at the end of a cycbox/examples/*.lua file). Settings detected at runtime are omitted.

{
"app": {
"app_transport": "tcp_server_transport"
},
"tcp_server_transport": {
"tcp_server_transport_bind_address": "0.0.0.0",
"tcp_server_transport_bind_port": 8080
}
}