3

At which point in message transmission from client to host (or vice versa) is the message actually sliced into packets?

From my current understanding, the application puts an entire file in the socket and hands it over to TCP entirely. TCP first buffers the file/message, and when the time is right (when is the time right?) cuts chunks of the buffer data (creates packets) and adds TCP headers to transform chunks into segments.

Why do we talk about packets in the application layer, if there are no packets in the application layer at all? Just whole files... This doesn't add right.

Can someone confirm my understanding?

sanjihan
  • 5,592
  • 11
  • 54
  • 119

2 Answers2

5

A TCP-based application has a message to send. What the message is depends on the application — it could be just a small request, or a whole file. It passes the message to the transport layer (TCP), which chops up the message into segments and passes them one by one to the network layer (Internet Protocol). The network layer adds a header to each packet, and passes it to the link layer (Ethernet), which handles frames.

So, in principle, we have:

  • messages at the application layer;
  • segments at the transport layer;
  • packets at the network layer; and
  • frames at the link layer.

In practice, however, people are not that pedantic, and tend to mix the notions up. You'll often hear people speak about TCP packets (the correct term would be IP packets with a TCP payload), and they will even speak about the application sending packets (the correct formulation would be that the application passes messages to the transport layer). Most of the time the inexact terminology is not a problem, since context disambiguates things.

jch
  • 5,382
  • 22
  • 41
  • 1
    Using the term _message_ with a streaming protocol easily will confuse novices. _message_ is too often misread as _datagram_ from related protocols (e.g. UDP). With streaming protocols you are - at the application layer - sending (sequences of) bytes . However, you could label each passing of such a sequence of bytes to the lower layer (usually operating system API) a _message_ in the terminology of your explanation. – rpy Jun 14 '16 at 10:29
  • What term do you use for the unit of information passed from the application to the transport layer? I like *message*, and I believe that the term is standard, but I'm quite willing to change my mind if you have a better term. – jch Jun 15 '16 at 09:54
  • I'm not sure what a good term would be. I'd go with _message_, but would add that application layer might send arbitrary sequences of byte to API layer and those calls would form _messages_ in a general sense. You might also add some remark explaining that with TCP a _message_ also could be joined with earlier or later messages before being chopped into segments . So, a message is not a natural border for forming segments (and packets) further down. – rpy Jun 15 '16 at 18:11
  • I agree, and it's even more complicated than that. I often accumulate multiple messages in a buffer in the application and push them all down in a single call to `write` or `writev`. But I still feel the explanation above is the best I can do without getting into these squalid details. – jch Jun 16 '16 at 10:49
1

The data are sliced into, and encapsulated by segments at the transport layer (UDP, TCP). The segments are encapsulated by packets by the network layer (IPv4, IPv6, etc.). The packets are encapsulated by frames at the data-link layer (ethernet, etc.).

Ron Maupin
  • 6,180
  • 4
  • 29
  • 36