+8618758069661 [email protected]
Product Search Guide: space = AND, | = OR, ! = NOT

Got any Questions? Call us Today!

+8618758069661

Or leave us a message

Online Message

Serial Device Servers and TCP Streams: Why Reads Split or Combine Messages

Views: 262 +3Original by FCTELEAuthor: FCTELE Technical Team
AT A GLANCE

Why does one TCP read not necessarily contain one complete serial-device response?

UART timing reconstructs characters, while the device's application protocol defines messages. The server buffers bytes and TCP delivers an ordered stream whose read boundaries can change. A correct receiver retains incomplete bytes and extracts validated messages using the actual protocol. Verify counts, order and payload under varied read sizes; changing packetization delay cannot replace correct parsing or unlimitedly protect a blocked serial input.

Three mechanisms and their verification boundariesFollow the signal, then verify the actual service

01Reconstruct characters

Reconstruct charactersUART start, data and stop timing define characters rather than business messages.S01234567TIllustrative 8N1 characterS: start · 0–7: data · T: stopUse the actual device character settings

UART start, data and stop timing define characters rather than business messages.

02Allow changing read boundaries

Allow changing read boundariesThe same ordered bytes can arrive through several valid read groupings.ABCDEFABCDEFSame ordered bytesRead boundaries are not command boundaries

The same ordered bytes can arrive through several valid read groupings.

03Keep parser state

Keep parser stateAppend bytes, validate complete messages and retain the trailing partial message.Append bytesComplete?ValidateKeep partial tailExtract valid messages; retain remaining bytes

Append bytes, validate complete messages and retain the trailing partial message.

Swipe to compare the three diagrams →

Conceptual teaching illustrations—not measured waveforms, installation wiring or the internal architecture of a specific product.
  • Reconstruct characters

    Match the actual serial format at both ends.

  • Allow changing read boundaries

    Test deliberate fragmentation and combined messages.

  • Keep parser state

    Bound lengths and define recovery after invalid data or reconnect.

Selection and verification checklistExpand the checks and related guides
Checks for this service and its actual operating conditions
CheckWhat to confirmHow to verify
Reconstruct charactersUART start, data and stop timing define characters rather than business messages.Match the actual serial format at both ends.
Allow changing read boundariesThe same ordered bytes can arrive through several valid read groupings.Test deliberate fragmentation and combined messages.
Keep parser stateAppend bytes, validate complete messages and retain the trailing partial message.Bound lengths and define recovery after invalid data or reconnect.

FCTEL Original Technical Article · FCTEL Technical Team
First published: 2026-10-04 · Last modified: 2026-10-04

After an RS232 or RS485 device is connected to Ethernet, the data returned by one read is not necessarily one complete message from that device. Splitting and combining messages often reflects different boundaries at the serial, network, and application layers rather than lost data. Understanding these layers makes it possible to build a reliable parser and locate the actual cause of a fault. This article explains general mechanisms. Supported modes, buffer behavior, and parameter ranges for a particular FCTEL product must be checked in its manual.

Open the original image for detail. Scroll the diagram horizontally to read all labels at full size.

UART 8N1 timing and serial receive buffer

Figure 1. A UART frames individual characters. An application protocol defines how bytes form a message.

UART frames characters; the application protocol defines messages

A UART normally starts a character with a start bit, sends the agreed number of data bits, optionally adds parity, and finishes with a stop bit. The receiver reconstructs the character using its configured baud rate and format. Baud rate, data bits, parity, and stop bits must match. Incorrect levels, noise, or sampling errors can therefore cause character errors before networking becomes relevant.

With 8N1, an eight-bit byte also requires one start bit and one stop bit: ten bit times in total. At an illustrative 9,600 bit/s, a character occupies about 1.04 ms. This is a calculation example, not a product performance specification. It explains why useful byte throughput is lower than the nominal bit rate and why a buffer must accept arriving characters.

RS232, RS422, and RS485 describe different electrical interfaces and connection arrangements; UART describes character timing. None defines an application message by itself. A temperature query may contain several bytes. The equipment must separately define its message boundary through a length, delimiter, fixed format, or protocol-specified timing interval.

How a serial device server connects the two mechanisms

In the receiving direction, the serial interface first reconstructs bytes from electrical signals. Bytes enter a FIFO or software buffer. Packetization logic then submits a portion to the network stack according to its implemented length or waiting conditions. In the other direction, bytes leave the network receive buffer and are transmitted character by character by the UART. Each direction has its own buffering and scheduling.

An application message can span several serial receive batches, and one batch can contain multiple messages. Packetization trades waiting time against transmission efficiency; it does not automatically understand every higher-layer protocol. FCTEL public serial server documentation includes TCP server and TCP client operating modes. Whether a particular framing strategy exists, and the names and ranges of its settings, must be checked in the relevant model manual.

If a serial source continues sending while the uplink is blocked, buffer occupancy grows. TCP backpressure can limit network transmission, but cannot make a serial source without suitable flow control stop. Buffer capacity, supported hardware or software flow control, source behavior, and disconnection policy must be assessed together. Reliable TCP transport does not imply unlimited loss-free operation under arbitrary congestion.

Open the original image for detail. Scroll the diagram horizontally to read all labels at full size.

TCP byte stream and alternative read boundaries

Figure 2. Two successful read patterns deliver identical ordered bytes while splitting and combining application messages.

TCP preserves byte order, not individual send boundaries

TCP presents a connection as an ordered byte stream. Sequence numbers identify byte positions; acknowledgments, retransmission, and flow control manage transport. A TCP segment is a network transport unit, while a business message belongs to the application protocol. One sender call does not require the receiver to obtain that same amount through one read.

Suppose equipment generates a six-byte message A followed by a four-byte message B. Successful transfer delivers the same ten bytes in the same order. The program might first read the first two bytes of A, then the remaining eight bytes, or read all ten at once. These are often called splitting and combining messages. By themselves, neither indicates corrupted data when the bytes are complete and ordered.

A read length depends on available data, receive buffering, thread scheduling, and interface arguments. Network segmentation also depends on the path and stack. An application cannot infer a business message length from a captured TCP segment length or treat every read return as one device response. When a connection closes, it must still handle complete received data and identify a trailing partial message.

Open the original image for detail. Scroll the diagram horizontally to read all labels at full size.

Stateful receive buffer and length-based parser

Figure 3. A fictional protocol illustrates incomplete-frame retention, validation, delivery, and preservation of trailing bytes.

A robust parser keeps state across reads

Maintain a persistent byte buffer. Each read appends data. The parsing loop first checks whether the header is available, then applies the protocol length or termination rule. Only a complete message should be validated and delivered to the business layer. Keep incomplete bytes for the next read; parse multiple complete messages individually without discarding the remainder.

For a custom protocol containing a synchronization marker, length, payload, and checksum, specify whether length includes the header, byte order, maximum permitted size, and checksum coverage. The diagram uses a fictional explanatory format, not a FCTEL protocol. Use the actual equipment protocol in a deployment, bound buffer growth, and reject impossible lengths. Define resynchronization after validation fails so that one bad byte does not misalign all following messages.

Delimiter-based protocols must handle escaping or delimiter values inside binary payloads. Fixed-length protocols must account for message types with different lengths. For timing-based serial protocols, distinguish an interval observed on the serial wire from the arrival time seen by a network application. Buffering and scheduling can change those intervals; the gap between TCP reads is not automatically the original serial inter-frame gap.

What packetization waiting time changes

A longer wait may combine more serial bytes before submission and reduce small-transfer overhead, but can delay the first byte. A shorter wait may forward bytes earlier and expose more partial messages to the application. Neither replaces correct parsing. Optimize business latency and integrity instead of demanding one message per read.

For request-response communication, consider device processing, serial transmission, server buffering, network round-trip time, and application scheduling separately. Set timeouts to cover these stages using controlled tests. Retry behavior must respect business semantics: determine whether write or action commands are safe to repeat rather than blindly resending indefinitely after a timeout.

Acceptance testing must cover content, timing, and recovery

Use recognizable sequence numbers and lengths in controlled tests. Cover isolated messages, back-to-back messages, fragmented input, long payloads, and short pauses. Run the same parser with deliberately different read sizes and verify the final message count, order, payload, and validation results. This provides stronger evidence than a terminal window that merely looks normal. Record examples as test inputs, not customer measurements.

Then test mismatched serial formats, uplink interruption, congestion, and reconnection separately. Distinguish serial character errors from network retransmission, buffer overflow from normal splitting, and business timeout from integrity failure. Record input byte counts, parsed messages, residual buffer contents, error causes, and recovery times; preserve the time references used for packet captures and serial logs.

When selecting a FCTEL serial device server, check its real interfaces, operating modes, flow control, and disconnect behavior. The key engineering distinction is that the server connects and transports data, the application protocol defines messages, and the parser reconstructs them across reads. Clear responsibilities prevent normal stream behavior from being mistaken for a hardware fault.

Technical references: IETF RFC 9293, TCP byte-stream service. Related FCTEL resources: Technical Articles and serial device server product documentation (Chinese).

Common practical questions

Does a correct UART character format establish the length of a device command?

No. Baud rate and framing recover characters; the application protocol still defines how those bytes form commands and replies. Check its length, delimiter or specified timing rules separately from the serial electrical interface.

Can increasing serial-server packetization delay guarantee one protocol message per TCP read?

No. It changes buffering and transmission timing, but the receiver's reads can still split or combine data. Reconstruct messages using the actual protocol, and measure latency instead of trying to force TCP to preserve sender-call boundaries.

What should a parser do when a TCP read ends halfway through a serial reply?

Retain the incomplete bytes for the next read, subject to the protocol's limits and timeout rules. Deliver only a complete validated message, preserve trailing data and define resynchronization; do not discard the partial message merely because the read returned.

Sources and applicable boundaries

These additions explain general mechanisms. Supported features, connection details and acceptance limits must be verified for the actual equipment, software and operating conditions; the diagrams are not measurements or certification evidence.

Share this article