Understanding TCP Through a Historical Analogy

Introduction: This article aims to discuss knowledge about TCP. Please forgive any inappropriate metaphors.

In the fourth year of the Tianqi era of the Ming Dynasty, early morning.

As dawn broke, I drove a horse-drawn cart full of goods to the South City Gate, which was the central location for handling goods. A line of carts arrived here, and the soldiers on the city wall, wearing helmets and armor, held long spears, vigilantly watching the movements below.

A noisy crowd gathered under the large shed at the gate, betting money. These guys all wore the same clothes, with the words “TCP Courier” written on their chests and backs.

I knew these were the people I was looking for; they would help me send the goods.

I got off the cart and looked around the shed, finding a bored young man sitting alone, drinking.

“Hey, courier, can you help me send this cart of goods?”

The young man lazily stood up and said, “Where are you from, and where do you want to go?”

I quickly took out the written address and said, “I live at 224 Beiguai Street in our city, and I need to send a cart of goods to the Neixiang County Office.”

“The Neixiang County Office has many gates; which gate will your goods enter?” The courier asked.

“The boss told me to send it to Gate 80 when we set off.”

The courier said, “Let’s go to the front.”

In front of the shed was a large open area. Perhaps we arrived early; now there were only me, the courier, and of course, my cart.

“Wait a moment, let me establish a connection with the Neixiang County Office,” the courier said, whistling, and a horse ran over.

He took a brush and wrote a letter on a piece of paper:
“County Office, I am from the capital, and I want to establish a connection with you. My serial number is 1024. Please reply upon receipt!”
The envelope read:
Shipping Address: 224 Beiguai Street, Capital
Receiving Address: Neixiang County Office, Gate 80

Then he placed the paper into the saddlebag on the horse’s back and patted the horse’s rear: “Let’s go.”

After two hours, the horse returned, and the courier took out the letter that the horse brought back, which read:

“Capital, I received your letter. Your letter contains a serial number of 1024, right? I agree to establish our connection; my serial number is 2048.”

The courier was overjoyed: “Look, the connection is about to be established; I just need to send them another letter.”

“County Office, I have received your confirmation letter, and I see your serial number is 2048. I am starting to send the goods.”

I asked him: “Is this the connection? I didn’t see you pull a wire to connect the capital and the county office.”

The courier said: “You don’t understand this; this is a TCP connection, which is virtual. The connection state information is not stored along the way; instead, it is maintained at both ends, that is, at my end and at the county office.”

“Then why do you have to send three letters?”

“This is the three-way handshake. Let me analyze it for you. The three-way handshake is mainly to verify that my sending and receiving capabilities and those of the county office are fine, which proves that the connection is good, and we can officially send the goods.”

First handshake: The capital sends a letter, and the county office receives it. At this point, the county office understands that the capital’s sending capability and its own receiving capability are fine.

Second handshake: The county office sends a letter, and the capital receives it. At this point, the capital understands that both its sending and receiving capabilities are good, and the county office’s sending and receiving capabilities are also fine. Otherwise, the county office would not receive the capital’s reply. However, the county office still does not know how its own sending function is. Therefore, a third handshake is needed:

Third handshake: The capital sends a letter, and the county office receives it. At this point, the capital has confirmed that both parties’ receiving and sending capabilities are fine. The purpose of this response is merely to eliminate the county office’s concerns about its sending function and the capital’s receiving function.

To be honest, I was a bit confused. The courier said: “Just think about it a bit more, and you’ll understand.”

I asked him: “Since you work so hard to establish a connection, don’t you personally deliver the goods?”

The courier said: “I wouldn’t do that! Since the new emperor ascended the throne, he has been busy like a carpenter, ignoring state affairs, leading to the people’s suffering, vast fields becoming wastelands, and robbers and wild beasts running rampant. No one dares to take the risk to deliver goods anymore. So the ministers in the cabinet thought of a way to build a network of official roads, allowing horses and donkeys to deliver goods. Even if they are eaten by tigers, it is no big loss. The Heavenly Empire is still quite people-oriented.”

“But how do these horses know to deliver my goods to the Neixiang County Office?”

“Don’t worry, they are all trained and will follow the official road. At every intersection, the court builds a post station where horses can eat grass, drink water, and rest. More importantly, the staff at each post station will check the letter I just wrote. They know the way and will lead the horse to a new correct official road to continue, ultimately reaching the Neixiang County Office. By the way, everyone gives these post stations a nickname: routers.”

“What if the horse gets lost or is eaten by a tiger and can’t arrive or return?”

“That’s the job of our TCP courier. You will see soon. Let me check your goods. Ah, your cabinet is too large; one horse can’t carry it. It needs to be divided into smaller packages, one by one.”

I had no choice but to break down the large goods into smaller packages.

“Let’s assign a number to each package,” the courier said. “This way, when they arrive at the Neixiang County Office, they can be assembled back together.”

Suddenly, I thought of a serious issue: “What if the horse is robbed? Wouldn’t one leg of my cabinet be lost?”

The courier, unfazed, said: “There’s nothing we can do. The cabinet ministers said that in this case, we need to resend that package.”

Oh, I felt a thousand alpacas running through my mind: these officials really don’t feel the pain of standing and talking. If one leg of the cabinet is lost, I still have to redo it.

The courier arranged the packages in order, 1, 2, 3, … 10, a total of 10 packages.

“According to regulations, we can send a maximum of 3 packages at a time, in order, first sending packages 1, 2, and 3,” the courier said, calling over three horses to load the goods, and the horses ran off quickly.

I waited anxiously, afraid that one package might be lost.

But how do I know if the packages have arrived at the county office?

The courier seemed to see my concern and took out an hourglass from his pocket: “If the sand runs out and the county office hasn’t confirmed, then it’s lost, and we have to resend it.”

After an hour, the long-awaited horse from the county office finally arrived, and the letter inside said: Package 1 has been received.

“Alright,” the courier said, “the county office confirmed the receipt of package 1, so we can send another one.” He called over a horse and sent out package 4.

Now I understood a bit. The courier’s method was to ensure that there were only 3 packages sent out at a time without confirmation.

After a while, the county office sent three horses at once, bringing back confirmations for packages 2, 3, and 4.

The courier said: “Looks like you’re lucky. I’ll send out packages 5, 6, and 7.” As he said this, he flipped the hourglass and started the timing again.

The confirmation for package 5 came quickly, and the courier sent out package 8. Thus, there were still three packages sent but not confirmed.

Now packages 6, 7, and 8 had all been sent out, but the confirmation for package 6 was delayed, and I was anxious.

At this moment, the hourglass ran out, and I looked at the courier uneasily.

He seemed indifferent: “Oh, it timed out. The horse carrying package 6 might have been eaten by a tiger, and the county office didn’t receive it.”

“What should we do?” I asked anxiously.

“We have to resend from package 6. Package 6 happens to be a leg of the cabinet, so go back and tell your boss to make another leg for the cabinet, ensuring it is exactly the same as the one sent before.”

I asked him: “What about packages 7 and 8? Did the county office receive them?”

“We still don’t know. If they received them, they will temporarily store them. If not, we will have to resend them like package 6.”

My patience reached its limit, and I really wanted to jump up and hit the courier.

Calming down, I thought and said: “No, why did you send three packages at once? Can’t you send one and wait for confirmation?” I’ll sue you.”

The courier said: “Suit yourself; you won’t win anyway. This is determined by the cabinet’s chief minister. What we use is called the sliding window protocol. If the window N=1, that means sending one and waiting for confirmation for one, which would be too slow. I can’t be occupied by you all the time, so we set a larger value for N, for example, N=3, to work like an assembly line, sending packages while receiving confirmations, making it faster.”

I had no choice but to go back and ask the boss to make the cabinet leg, which wasted a lot of time.

The courier sent out package 6 again and started timing again.

The confirmation for package 6 still hadn’t arrived! Package 7’s confirmation hadn’t arrived either, but the confirmation for package 8 arrived first!

The courier said: “Hmm, not bad. The confirmations for packages 6 and 7 are probably lost on the way. It doesn’t matter; as long as the county office says they received package 8, it implies that packages 6 and 7 were received too. Otherwise, they wouldn’t send the confirmation for package 8.”

Next, packages 9 and 10 were sent out, and this time it went well. Finally, all the packages were sent out.

The Neixiang County Office also assembled the cabinet. My task was finally completed.

Later, I learned that the county office had actually received package 6; it was just that their confirmation package sent back to the capital got lost on the way, which led to us resending it.

I understood that this so-called TCP is merely establishing a reliable sending method based on those unreliable horses for transportation, fundamentally just a resend upon failure, and the ones suffering are still us common folks.

I paid the courier 2 taels of silver as a fee, pulled my cart, and left without looking back.

I heard the courier shout behind me: “Welcome back! The cabinet chief is researching a new protocol; you must come back to try it next time!”

I ignored him because I never wanted to come back to this hellish place again!

Popular Articles

I Am a Thread

I Am a Java Class

Javascript: A Loser’s Comeback

Little Wang’s Path to Architect

CPU Forrest Gump

Why IE Injured Chrome and Firefox

Node.js: I Just Need a Shop Assistant

If I Were a Computer Science Teacher

If Time Could Turn Back, I Would Learn Java This Way

Learn Programming, Not Just Java

7 Lessons from 15 Years of Programming Experience by a Senior Architect

Understanding TCP Through a Historical Analogy
WeChat Official Account: Programmer’s Turnaround
“Programmer’s Turnaround” is created by a former IBM architect with 15 years of experience, sharing lessons and experiences in programming and the workplace.

Leave a Comment