In the last months, important improvements to the Ethercard library have been made and it’s now possible to send data divided in multiple TCP packets: let’s see how to do it…
A bit of theory
Internet communications leverage a stack of protocols, that is a group of different protocols, each specialized to do a particular job. During the transmission, a protocol creates its data packet and sends it to the lower protocol, until it reaches the protocol that handles the physical layer, which translates the data into electrical signals and sends them through the cable:
At each step, the packet is enriched with the information necessary to the different protocols for doing their jobs. In addition, each protocol may fragment a packet from the protocol above in multiple packets.
When you access an Internet site, your browser uses the HTTP protocol to communicate with the target webserver. The request is then encapsulated within one or more TCP packets, which are then included in packets by the lower protocols until they are sent on the network. When they reach the server, they are in turn processed by the protocols in the reverse order, until the original request is passed to the webserver application that “understands” the HTTP protocol:
If the browser‘s request or the response from the webserver contains a huge number of bytes, the TCP protocol can fragment the data in multiple packets. Each TCP packet contains some flags, that are fields that carry information for the receiver. For each packet correctly received, a confirmation ACK is sent, while the last packet of a transmission has the FIN flag set to 1, to indicate the end of the transmission.
The Ethercard library now offers the ability to forge packets specifying which TCP flags they contain.
If we are developing a simple web server, like in today’s example, we can therefore:
- when the request is received, send an ACK packet to confirm the correct reception
- split the response in multiple packets, each one of them containing only the ACK flag
- send the last packet with both ACK and FIN flags
The methods we’re going to use are:
sends an ACK packet (without data)
sends a packet with size bytes and the specified flags.
in the next page, I’m going to analyze the Arduino’s sketch…
Pages: 1 2