Ask coding questions

← Back to all posts
What does a TCP do?
DynamicSquid (5029)

Clients send packets of information to a server directed through routers. Sometimes, the packets may travel through different routers or may be delayed in their arrival. For this problem, the TCP checks to see if all packets have arrived.

But how does the TCP work? Does it establish a direct connection between server and client? And if so, then why do we even need the TCP? Why can't the server tell the client that not all information was sent?

Answered by CSharpIsGud (1070) [earned 5 cycles]
View Answer
Comments
hotnewtop
CSharpIsGud (1070)

You will commonly see TCP called TCP/IP, because TCP is the protocol used to transmit data from one end to the other over IP.
It does more than just check that the data is correct. The packets could also arrive out of order, or not at all.

And if so, then why do we even need the TCP? Why can't the server tell the client that not all information was sent?

TCP is the exact reason the server can tell the client that.

TCP at a basic level just splits data into segments along with a checksum and some other fields, but most importantly a sequence number.

  • Segment 3 could arrive before segment 2, but with TCP, the server can acknowledge that it got 3 before 2 and tell the client to resend segment 2.

  • Now segment 2 could have just been delayed instead of dropped, in that case there might be duplicate segments arriving now, but since they have sequence numbers the receiving machine will ignore any segments it already has.

Some less widely known features of TCP, is that clients using it can actually tell the other client how many bytes it is willing to receive in a response. If the server is under very heavy load it can even be set to 0, meaning any complying clients won't send anything until it increases it, allowing the server to keep up.

TCP even tests the network for how much it can send before it gets overloaded, and limits data sent if it's on an overloaded network.

DynamicSquid (5029)

@CSharpIsGud That makes more sense, thanks! I guess I was thinking of the term "protocol" like an actual thing, but it's more like a set of rules right?

InvisibleOne (3227)

From the limited amount, I know from the internet and working with a lot of networking stuff setting up security cams.
TCP is the protocol for insuring packages are legit. It set's up a start point and destination sort of like the IP protocol, but then breaks the packages into smaller pieces and routes them through the network to their location. On each package, it adds integrity codes to make sure everything gets to the other end more securely and not in a jumbled mess. But I'm sure other people explain it better them me.