When you have raw data (ie a byte-array) and you want to send it over a network, then you need some sort of encoding:
- If you send multiple blocks (whole arrays), the recipient needs to be able to differentiate between the end of one and the start of the next.
- If the data is really large its is better to split it into smaller blocks (yes, packets) to play well with other users of the network.
- You need to know that the data is error-free at the client as networks have the tendency to be unreliable at exactly the wrong time for you.
Encoding solves the first point above.
TCP is the conventional solution to the second two points.
Examples of encoding are:
- HTTP encodes the length in cr delimited lines, then a pure binary blob.
- Text Files could be ctrl-z delimited.
- XML can be delimited simply by its syntax of tags.