Brain Dump

TCP

Tags
networking

Is a bidirectional protocol used to reliably transmit data between two machines in a network.

TCP is built atop the IP (IPv4/IPv6) protocols, using them for negotiating a connection, which is why it's often referred to as TCP/IP. Any packets sent through TCP must send acknowledgements of the packets it sees back to the sender. If the acknowledgement doesn't arrive within some timeout the sender resends the packet. TCP also attaches a sequence number to each packet so the receiver can re-build the original file in case the packets arrive out of order. If there's been no transfer for a short interval TCP will trade zero-length packets to ensure the connection is still alive.

To form a connection the client sends a SYN (synchronisation) packet that tells TCP what starting sequence to start on. The receiver will return a SYN-ACK (synchronisation acknowledgement). The client will then acknowledge that with one last ACK (acknowledgement) package. To terminate the connection either side can send a FIN (finish) packet. Note: The FIN packet can be configured to close only the read or write end of a particular connection.

Warn: TCP is naturally connection oriented. Applications communicating over TCP have to find unique ways of telling each other that a request or response is over. For example HTTP delimits the header through two carriage returns and uses either a length field or one keeps listening until the connection is closed.

Links to this note