TCP

Introduction

In computer networking, networks protocols are the rules computers follow to communicate.

TCP, or Transmission Control Protocol, is a foundational protocol that ensures reliable communication between computers. It’s like an orchestra conductor, ensuring that different computers communicate clearly and reliably.

In this article, we’ll explore TCP in simple terms, breaking down its basic concepts and how it helps computers chat, all while explaining how Computer A and Computer B keep track of the connection using sockets and how to visually see this connection using Wireshark .

TCP Basics

To understand TCP, let’s start with some essential words:

  • Protocol: Consider this a rulebook that computers follow to talk to each other. It’s like having a common language.
  • Connection-oriented: Before computers send messages, they first introduce themselves and shake hands, like making a new friend.
  • Reliable: When TCP sends a message, it makes sure it arrives safely without any mistakes, like sending a letter with a confirmation receipt.
  • Ordered: TCP guarantees that messages arrive in the same order they were sent, just like reading a story from start to finish.

Setting Up a TCP Connection

Imagine two computers, Computer A and Computer B, wanting to share information. Before sending messages, they must do a special “hello” dance. Here’s how it works:

Connection Setup:

  1. Computer A says, “Hello, I want to talk!” by sending a special SYN (Synchronize) message to Computer B.
  2. Computer B replies, “Hello back! Let’s talk,” with a message called SYN-ACK (Synchronize-Acknowledgment) back to Computer A.
  3. Computer A then says, “Got it! Let’s chat,” by sending an ACK (Acknowledgment) message to Computer B.

This dance is essential. If any of these steps fails, the computers won’t be able to talk to each other.

Seeing the Dance with Wireshark

To visualize this dance, you can use a tool like Wireshark, which shows you the messages computers send each other. Here’s how:

  1. Download and install Wireshark.
  2. Open Wireshark and choose which part of your computer’s “conversation” you want to watch.

To find the right part, you can use a command on your computer (like “netstat -r -n” on Linux or macOS) to figure out which “line” represents your connection.

  1. Connect to a server (like fellas.systemsatscale.io) on a specific port (like 4242) using a tool like NetCat:
nc fellas.systemsatscale.io 4242

Focus on the first three messages:

  • The first message is like Computer A saying, “Hello, let’s talk!”
  • The second message is Computer B responding, “Sure, let’s talk.”
  • The third message is Computer A confirming, “Great, let’s chat!”

Once this dance is done, the computers are connected and can send messages. Computers A and B keep track of this connection using sockets, so they know who is talking to whom. If Computer A didn’t do this “hello” dance, Computer B would ignore Computer A’s messages.

How Computer A and Computer B Keep Connection State Using Sockets

You might wonder how Computer A and B remember this connection. Imagine it’s like two friends at a party who keep notes about who they are talking to.

When Computer A and Computer B complete the “hello” dance:

  • They create a special “socket” to represent their connection. This socket holds all the information about their conversation.
  • They remember that Computer A started the conversation, and Computer B responded.
  • They know that something went wrong if Computer A didn’t confirm with that final ACK message.

This socket is like a phone line between Computer A and B, ensuring messages go to the right place. If a new computer, Computer C, tries to join the conversation, Computer A and B will create a new socket to remember their interaction, keeping everything organized.

Conclusion

TCP is like the computer orchestra’s friendly conductor, ensuring messages get delivered reliably and in the correct order. Understanding the “hello” dance, how messages are sent in pieces, and the role of sockets is critical to grasping how computers communicate over the internet. Computers A and B play friends at a party, ensuring everyone uses their dedicated sockets to talk to the right people.