A robot telemetry sender can write two complete application records while the receiver obtains them in three different-sized reads. The receiver has not necessarily lost bytes or received corrupted data. Its mistake may be treating each read as one application record.

TCP provides a stream abstraction. Application record boundaries must come from the protocol layered on that stream. A buffer size passed to a receive call describes capacity for that call; it does not declare the size of the next complete robot measurement.

Python's Socket Programming HOWTO discusses partial sends, partial receives, and application framing. Its socket API reference defines recv's maximum byte count and empty-byte return. The stream below is an original hypothetical byte ledger, not a packet capture, executed program, or performance measurement.

Invent a small record format

Define a demonstration protocol with a two-byte unsigned length header in big-endian order. The value counts payload bytes only, excluding the header. For this invented format, valid payload lengths are one through 100 bytes.

The small maximum is a stated rule for the example, not a recommendation for robot communications. No checksum, authentication, message identity, or timestamp field is included in this deliberately limited format.

Record A contains the three ASCII payload bytes ABC. Its complete encoded form, in hexadecimal, is 00 03 41 42 43. Record B contains five ASCII bytes DEFGH, encoded as 00 05 44 45 46 47 48.

Placed back to back, the records occupy 12 stream bytes: four header bytes plus eight payload bytes. Their exact application boundaries are after stream byte five and after stream byte twelve when positions are counted from one.

Change read boundaries without changing the stream

One valid delivery to the application is a single read containing all 12 bytes. Another is two reads of five and seven bytes, coinciding with the records. A third is three reads of one, five, and six bytes.

For that third partition, the first read contains 00. The second contains 03 41 42 43 00. The third contains 05 44 45 46 47 48. Concatenating the three results recreates exactly the same stream.

The first read has only half a header. The second completes record A and already contains the first byte of B's header. The third completes B. None of these read boundaries can replace the declared length format.

The example makes no claim about which partition a real system will produce. Several application writes may be observed together, and one write may require several reads. The parser must tolerate partitions consistent with the stream abstraction.

Keep incomplete data between calls

Consider a parser that maintains a pending-byte buffer. After the first read, it has one byte, fewer than the two needed to decode a length. It retains that byte without emitting a record.

After the second read, the buffer contains six bytes: 00 03 41 42 43 00. The first two decode to length three. Five bytes are therefore enough for the first complete record: two header bytes and three payload bytes.

The parser emits ABC and consumes exactly those five bytes. The remaining 00 stays pending as the first byte of the next header. Discarding it would shift the interpretation of everything that follows.

After the third read, the pending buffer is 00 05 44 45 46 47 48. It contains a length-five header and five payload bytes, so the parser emits DEFGH and consumes seven bytes. The pending buffer becomes empty.

This ledger specifies parser behavior, not runnable production code. Error handling, concurrency, resource limits, and protocol semantics need their own implementation decisions.

A large receive request does not solve framing

Suppose a receiver requests up to 4,096 bytes. That number is an upper bound for the returned data, not a promise to wait for one complete application record or return exactly 4,096 bytes.

If all 12 example bytes arrive together, a parser that assumes one record per read would incorrectly combine A and B. If a read returns only the first header byte, a parser that assumes the header is always complete would fail before considering the payload.

The parser should inspect its accumulated buffer repeatedly: determine whether a header is complete, validate the length, determine whether that record is complete, consume it, and then examine any remainder for another record. A loop over complete buffered records handles coalesced arrivals as well as split ones.

Read capacity and application maximum are separate quantities. A 100-byte payload limit does not mean every receive buffer must be exactly 100 bytes or that every record has that length.

Byte counts are not text-character counts

The declared length measures encoded bytes. ASCII keeps this example simple because each displayed payload character occupies one byte. Other text encodings can represent one character with several bytes.

A sender that counts characters before encoding while a receiver counts bytes can disagree about the next record boundary. A length prefix needs a defined encoding boundary, just as its integer needs a defined width and byte order.

Arbitrary byte payloads can also contain zeros. Treating zero as an implicit terminator would conflict with the specified length-delimited format. Header zeros in this example are valid data, not evidence that the stream has ended.

Closure and incomplete records

For an ordinary positive-size stream recv call under the documented interface, an empty bytes result indicates the peer has disconnected. If closure occurs with only one pending header byte, the parser has an incomplete record, not a valid zero-length payload.

Similarly, a complete header declaring five payload bytes followed by only three before closure leaves a truncated application record. The bytes already received do not establish that the missing two can be invented or that the partial payload should be delivered as complete.

This format excludes zero-length payloads by definition. A different protocol could allow them, but would still need to distinguish a length field containing zero from the receive operation returning no bytes.

Completion at one layer has limits

Successfully assembling a telemetry record establishes that its bytes meet the framing rule. It does not establish that a robot executed a command, that a measurement is fresh, or that the peer is authorized. Those are separate application and security claims.

Keeping stream bytes, parser state, record identities, and application acknowledgments distinct makes a communication trace explainable. Read boundaries can then change without silently changing the meaning of the records.

Sources checked October 23, 2026: Python Socket Programming HOWTO, web edition titled Python 3.15.1 when accessed, Using a Socket and Binary Data: https://docs.python.org/3/howto/sockets.html

Python socket API, same accessed edition, recv and send contracts: https://docs.python.org/3/library/socket.html

Illustration note: A generic robot and computer scene is a concept illustration. It is not a network capture, a verified TCP implementation, or evidence that the invented records reached a physical robot.